Python: 从网页下载文件,ashx
Python: download file from webpage, ashx
在 this 网页上有一个 "Export to Excel" 按钮。
与此 link 关联的命令应为:
如何从 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>>
您可以使用 requests 模块:
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)
在 this 网页上有一个 "Export to Excel" 按钮。 与此 link 关联的命令应为:
如何从 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>>
您可以使用 requests 模块:
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)