I need to download several files via http in Python.
The most obvious way to do it is just using urllib2:
u = urllib2.urlopen('http://server.com/file.html')
localFile = open('file.html', 'w')
Download scripts like that tend to push a header telling the user-agent what to name the file:
Content-Disposition: attachment; filename="the filename.ext"
If you can grab that header, you can get the proper filename.
There's another thread that has a little bit of code to offer up for
remotefile = urllib2.urlopen('http://example.com/somefile.zip') remotefile.info()['Content-Disposition']