2017-05-28 35 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

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