My script logs in to my account, navigates the links it needs to, but I need to download an image. This seems to be easy enough to do using urlretrive. The problem is that the src attribute for the image contains a link which points it to the page which initiates a download prompt, and so my only foreseeable option is to right click and select 'save as'. I'm using mechanize and from what I can tell Mechanize doesn't have this functionality. My question is should I switch to something like Selenium?
Asked
Active
Viewed 200 times
2 Answers
0
Mechanize, last I checked, was pretty poorly maintained and documented. Selenium has a much more active community.
That being said: why do you need mechanize to do this? Why not just use urllib?

Community
- 1
- 1

Patrick Collins
- 10,306
- 5
- 30
- 69
-
I didn't use urllib because I don't have the url of the image. – Dallin Jun 04 '14 at 02:55
-
Surely you can find it. Mechanize is basically undocumented, so there may be a more elegant response, but in the very worst case you can use `response.read()` to grab the full HTML of the page, BeautifulSoup to parse it and find your desired image, then urllib to grab the image itself. If you can find the image in mechanize, you can definitely find its url. – Patrick Collins Jun 04 '14 at 02:59
-
Ok I realized the reason I'm having a problem is that the url from 'src' contains an .mhtml file with a base64 string. I've never dealt with MHTML before, so I'm doing some research. – Dallin Jun 04 '14 at 17:33
0
I would try to watch Chrome's network tab, and try to imitate the final request to get the image. If it turned out to be too difficult, then I would use selenium as you suggested.

Fabricator
- 12,722
- 2
- 27
- 40