How do I download a file with progress report using python but without supplying a filename.
I have tried urllib.urlretrieve but I seem to have to supply a filename for the downloaded file to save as.
So for example:
I don't want to supply this:
urllib.urlretrieve("http://www.mozilla.com/products/download.html?product=firefox-3.6.3&os=win&lang=en-US", "/tmp/firefox.exe")
just this:
urllib.urlretrieve("http://www.mozilla.com/products/download.html?product=firefox-3.6.3&os=win&lang=en-US", "/tmp/")
but if I do I get this error:
IOError: [Errno 21] Is a directory: '/tmp'
Also unable to get the filename from some URL Example:
http://www.mozilla.com/products/download.html?product=firefox-3.6.3&os=win&lang=en-US
You can download files from a URL using the requests module. Simply, get the URL using the get method of requests module and store the result into a variable “myfile” variable. Then you write the contents of the variable into a file.
Here is a complete way to do it with python3 and no filename specified in url:
from urllib.request import urlopen
from urllib.request import urlretrieve
import cgi
url = "http://cloud.ine.ru/s/JDbPr6W4QXnXKgo/download"
remotefile = urlopen(url)
blah = remotefile.info()['Content-Disposition']
value, params = cgi.parse_header(blah)
filename = params["filename"]
urlretrieve(url, filename)
In result you should get cargo_live_animals_parrot.jpg
file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With