2017-05-28 36 views
0

从数据库文件我想从这个网站下载202个国家的所有的Excel文件:下载多个Excel在Python

  1. 转到此链接: http://investmentpolicyhub.unctad.org/IIA/IiasByCountry#iiaInnerMenu

2.Click每个国家命名表中,例如:

安哥拉是在这里: http://investmentpolicyhub.unctad.org/IIA/CountryBits/5#iiaInnerMenu

  • 然后,单击“导出”,下载文件
  • 能否请你帮我如何做到这一点在Python?

    链接到每个国家的数量居然只有改变(例如5安哥拉)

    不过,我不知道如何编写代码来点击Excel的盒子和下载在Python :(

    谁能帮助我?

    非常感谢你!

    +0

    你到目前为止尝试过什么? – DexJ

    回答

    0

    您可以使用请求包下载的文件(右键单击该按钮才能看到该链接)

    import requests 
    
    url =('http://investmentpolicyhub.unctad.org/Download/ExportCountryBits/5?' 
         'sortColumn=InvolvedPartiesName&sortOrder=1') 
    res = requests.get(url) 
    res.raise_for_status() 
    
    # write the file to your current folder 
    with open('myfile.xlsx', 'wb') as f: 
        f.write(res.content) 
    
    +0

    你好喵,非常感谢你的帮助。它的作品非常漂亮。 –