Search code examples
pythondownloadpython-webbrowser

how to download from http url (e.g. with webbrowser) to a specific path location?


I want to give a specific path to save file downloaded from http url

the code below dumps the file to my Downloads directory.

import webbrowser

url = 'https://some_api_path&params=SOME_PARAMS&download=true'

webbrowser.open(url)

I need to control destiny path/filename of downloaded file (via chrome browser) in order to filter downloaded files based on params passed to api.


Solution

  • You can use module Requests

    import requests
    url = 'https://www.python.org/static/img/[email protected]'
    myfile = requests.get(url)
    open('./pythonlogo.png', 'wb').write(myfile.content)
    

    Saved File "pythonlogo.png" to the current folder!