0

I am trying to grab a PNG image which is being dynamically generated with JSP in a web service.

I have tried visiting the web page it is contained in and grabbing the image src attribute; but the link leads to a .jsp file. Reading the response with urllib2 just shows a lot of gibberish.

I also need to do this while logged into the web service in question, using mechanize. This seems to exclude the option of grabbing a screenshot with webkit2png or similar.

Thanks for any suggestions.

eli
  • 4,636
  • 7
  • 25
  • 29
  • looks like `Selenium` might be a good option for grabbing a screenshot after all, though running on a headless server would require a lot of configuration – eli Jan 06 '12 at 13:31

1 Answers1

1

If you use urllib correctly (for example, making sure your User-Agent resembles a browser etc), the "gibberish" you get back is the actual file, so you just need to write it out to disk (open the file with "wb" for writing in binary mode) and re-read it with some image-manipulation library if you need to play with it. Or you can use urlretrieve to save it directly on the filesystem.

If that's a jsp, chances are that it takes parameters, which might be appended by the browser via javascript before the request is done; you should look at the real request your browser makes, before trying to reproduce it. You can do that with the Chrome Developer Tools, Firefox LiveHTTPHeaders, etc etc.

I do hope you're not trying to break a captcha.

Giacomo Lacava
  • 1,784
  • 13
  • 25