我正在尝试使用Python和Requests包从网页导出Excel文档。你知道吗
注意:如果要单击浏览器中的链接,会出现一个新窗口,要求我打开或保存文件。
我使用请求来“获取”生成弹出窗口的页面,如上所述。你知道吗
此get请求指定类型:vnd.openxmlformats-officedocument.spreadsheetml.sheet
请参见下面的代码:
payload = {'username': 'name@domain.com', 'password': 'thisisit'}
with requests.Session() as s:
s.post('https://example.com/login', data=payload)
url = 'https://example.com/inquiry_detail?action=download_inquiry_items&inquiry_id=1'
r = requests.get(url, allow_redirects = True)
with open('foobar', 'wb') as f:
f.write(r.content)
我希望收到excel文件的二进制文件。相反,我只是从重定向中获取html,而不是文件的链接。你知道吗
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐