How to download a file with Python, Selenium and PhantomJS

后端 未结 4 561
无人及你
无人及你 2021-01-06 12:31

Here is my situation: I have to login to a Website and download a CSV from there, headless from a linux server. The page uses JS and does not work without it.

After

4条回答
  •  -上瘾入骨i
    2021-01-06 13:03

    You can try something like:

    from requests.auth import HTTPBasicAuth
    import requests
    
    url = "http://some_site/files?file=file.csv"  # URL used to download file
    #  GET-request to get file content using your web-site's credentials to access file
    r = requests.get(url, auth=HTTPBasicAuth("your_username", "your_password"))
    #  Saving response content to file on your computer
    with open("path/to/folder/to/save/file/filename.csv", 'w') as my_file:
        my_file.write(r.content)
    

提交回复
热议问题