I am looking for a quick way to download a file via HTTP, using a python one-liner from the command line (similar to the functionality of wget
or curl
). The idea is to enable a quick copy/paste to download distutils
on Windows.
I know of one solution (see my answer below). I'm interested in other solutions that consider the following:
distutils
here, it's unlikely we'll have access to requests
at this stage)Content-Disposition
The simplest solution I could come up with would be:
try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve
urlretrieve('http://example.org', 'outfile.dat')
urlretrieve
takes care of downloading the resource to a local file and can deal with large files.
It however ignores Content-Disposition
headers, if you want that to be considered, you'd need to use urlopen
and parse the response headers yourself. Content-Disposition
isn't a HTTP standard header, so i doubt you will find much support for it in the python http libraries...
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