0

I have a URL link that if I click on it, it will start downloading a file. The URL looks something like this:

http://somewebsite.com/download?f=someStrings

If I copy the URL and past it, in the URL bar of a web-browser it will start downloading as well.

How can I download the file using Python and preferably without using selenium.

TJ1
  • 7,578
  • 19
  • 76
  • 119

1 Answers1

0

You can download the file using the requests module:

import requests as rq
r = rq.get('http://somewebsite.com/download?f=someStrings', allow_redirects=True)
open('filename.extension', 'wb').write(r.content)

Some points to note:

  1. Replace http://somewebsite.com/download?f=someStrings with your desired URL

  2. Replace filename.extension with file name and its file extension.

  3. You can also specify the path where you want to save it
Roshan
  • 664
  • 5
  • 23