0

In python, How can I download a file. I see this link

Basic http file downloading and saving to disk in python?

But this assumes that you know the type of file you are downloading, but what if I have a link like

http://www.example.com?/factory.aspx?did=123

and this link opens an image or a pdf or a word file or anything really. How can I get the filename of it and save it to my disk. Cause if I visit the link, then the address bar is still the same (doesn't show the file name) but if i try to save the file, the default name in the save window is the actual filename.

Does anyone know how to do this?

Thanks

Community
  • 1
  • 1
omega
  • 40,311
  • 81
  • 251
  • 474
  • The filename is in the `Content-Disposition` header, [this might be useful](http://stackoverflow.com/questions/17495334/how-to-decode-the-filename-parameter-of-content-disposition-header-in-http) – Antti Haapala -- Слава Україні Apr 11 '15 at 06:42
  • I solved it with Kender's answer from http://stackoverflow.com/questions/862173/how-to-download-a-file-using-python-in-a-smarter-way. – omega Apr 11 '15 at 06:44

0 Answers0