【问题标题】:Python: download file from webpage, ashx [duplicate]Python:从网页下载文件,ashx [重复]
【发布时间】:2017-03-13 07:54:56
【问题描述】:

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

【问题讨论】:

    标签: python download urllib2 ashx


    【解决方案1】:

    您可以使用 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)
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-04
      • 2015-08-01
      • 2019-01-15
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      相关资源
      最近更新 更多