问题描述
我正在尝试下载一个上传到 Sharepoint 2013 网站的 excel 文件.
我的代码如下:
导入请求url='https:///.xlsx?Web=0'author = HttpNtlmAuth('','')response=requests.get(url,auth=author,verify=False)打印(响应.status_code)打印(响应.内容)
这给了我一个很长的输出,类似于:
x00docProps/core.xmlPK\x01\x02-\x00\x14\x00\x06\x00\x08\x00\x00\x00!\x00\x7f\x8bC\xc3\xc1\x00\x00\x00"\x01\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb8\xb9\x01\x00customXml/item1.xmlPK06\x05\x05x00\x00\x00\x00\x1a\x00\x1a\x00\x12\x07\x00\x00\xd2\xba\x01\x00\x00\x00'
我之前为另一个站点做过类似的事情,我得到了 xml 作为输出,这对我来说是可以接受的,但我不确定如何处理这些数据.
有什么想法可以把它处理成 xlsx 或 xml 吗?
或者可能以另一种方式下载 xlsx?(我尝试通过 wget 库进行下载,但 excel 似乎已损坏)
任何想法都会非常有帮助.
问候,卡兰
为时已晚,但我遇到了类似的问题...认为它可能对其他人有所帮助.
尝试将输出写入文件或在打印时应用一些编码.
写入文件:
file=open("./temp.xls", 'wb')文件.写(响应.内容)文件.close()
或
file=open("./temp.xls", 'wb')文件.写(响应.文本)文件.close()
带编码打印
print ( resp.text.encode("utf-8") )
或
print ( resp.content.encode("utf-8") )
!进行适当的导入.! 尝试使用 'w' 或 'wb' 进行文件写入.
希望这会有所帮助.
I'm trying to download an excel file which is uploaded on a Sharepoint 2013 site.
My code is as follows:
import requests
url='https://<sharepoint_site>/<document_name>.xlsx?Web=0'
author = HttpNtlmAuth('<username>','<passsword>')
response=requests.get(url,auth=author,verify=False)
print(response.status_code)
print(response.content)
This gives me a long output which is something like:
I did something like this before for another site and I got xml as output which was acceptable for me but I'm not sure how to handle this data.
Any ideas to process this to be like xlsx or xml?
Or maybe to download the xlsx another way?(I tried doing it through the wget library and the excel seems to get corrupted)
Any ideas would be really helpful.
Regards,Karan
Its too late but i got similar issue... thought it might help someone else.
try writing the output to a file or apply some encoding while printing.
file=open("./temp.xls", 'wb')
file.write(response.content)
file.close()
or
file=open("./temp.xls", 'wb')
file.write(response.text)
file.close()
print ( resp.text.encode("utf-8") )
or
print ( resp.content.encode("utf-8") )
!Make appropriate imports.!try 'w' or 'wb' for file write.
Hope this helps.
这篇关于我正在尝试使用 python requests 模块下载一个 excel 表并获取垃圾输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!