Python:从网页下载文件,ashx

2024-10-02 12:23:15 发布

您现在位置:Python中文网/ 问答频道 /正文

this网页上有一个“导出到Excel”按钮。 与此链接关联的命令应为:

https://www.animasgr.it/IT/Prodotti/Quotazioni-e-Performance/_layouts/15/GetExcel.ashx?type=QuoteFondo&code=A60A&i=03.06.1985&f=27.10.2016

如何从Python脚本调用此命令来下载文件? 我尝试的是:

response = urllib2.urlopen(https://www.animasgr.it/IT/Prodotti/Quotazioni-e-Performance/_layouts/15/GetExcel.ashx?type=QuoteFondo&code=A60A&i=03.06.1985&f=27.10.2016)

In [12]: response
Out[12]: <addinfourl at 4504653336 whose fp = <socket._fileobject object at 0x10cf9e550>>

Tags: https命令wwwtypeperformancecodeitlayouts
1条回答
网友
1楼 · 发布于 2024-10-02 12:23:15

您可以使用请求模块:

import requests

url_file = 'https://www.animasgr.it/IT/Prodotti/Quotazioni-e-Performance/_layouts/15/GetExcel.ashx?type=QuoteFondo&code=A60A&i=03.06.1985&f=27.10.2016'
resp = requests.get(url_file)

with open('anyfilename.xls', 'wb') as f:
    f.write(resp.content)

http://docs.python-requests.org/en/latest/

相关问题 更多 >

    热门问题