2016-10-31 168 views
0

this網頁上有一個「導出到Excel」按鈕。 與此鏈接相關的命令應該是:Python:從網頁下載文件,ashx

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>> 

回答

1

您可以使用請求模塊:

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)