views:

224

answers:

1

Hello, I've got an image on a page rendered by Firefox via Webdriver, I can get its object (wd.find_element_by_xpath("id('main')/form/p[5]/img")), but how can I get its body either base64-encoded or just a location on my hard drive?

PS: please don't suggest getting the src and fetching it with an external tool. I want the image I already have in the browser.

+1  A: 

Cached images can be extracted from Firefox's cache by navigating to an URL like this one:

about:cache-entry?client=HTTP&sb=1&key=http://your.server/image.png

The resulting page will contain a line with the "file on disk" label, like this one:

file on disk: /home/fviktor/.mozilla/firefox/7jx6k3hx.default/Cache/CF7379D8d01

This page will also contain the hex dump of the file's contents. You can load the file from that path or parse the hex dump. Please note, that the path can also be none in the case of small files cached only in memory. Your only option is parsing the hex dump in this case.

Maybe there's a way to suppress the hex dump if there's a cache file on the disk, but I'm not sure about it.

fviktor