views:

47

answers:

1

Hi

I have a form which when submitted by a user redirects to a thank you page and the file chosen for download begins to download.

How can I save this file using python? I can use python's urllib.urlopen to open the url to post to but the html returned is the thank you page, which I suspected it would be. Is there a solution that allows me to grab the contents of the file being served for download from the website and save that locally?

Thanks in advance for any help.

+2  A: 

If you're getting back a thank you page, the URL to the file is likely to be in there somewhere. Look for <meta http-equiv="refresh"> or JavaScript redirects. Ctrl+F'ing the page for the file name might also help.

Some sites may have extra protection in, so if you can't figure it out, post a link to the site, just in case someone can be bothered to look.

Matti Virkkunen
Cool, I'll have a look. The file is stored in a database and is generated by selecting it's blobs and joining them together. I trust that it generates a temporary file in order to deliver it.
Martin
@Martin: It doesn't necessarily have to be a physical file, it might as well be generated by some kind of script/handler on the fly, but in any case it will have a URL. Otherwise a browser wouldn't be able to access it.
Matti Virkkunen
Thank you, it turned out to be some javascript window.location.
Martin