|
From: Tom A. <tom...@e2...> - 2009-08-04 22:37:16
|
On Tue, 4 Aug 2009, Jack Smith wrote:
> Hello. Im new to htmlunit, can you help me with one issue, please ?
>
> If i do this:
>
> WebClient webClient = new WebClient(BrowserVersion.FIREFOX_2);
> HtmlPage page = webClient.getPage(someurl);
>
> Page is loaded fine, but without images. What is the best way to make
> htmlunit load all images too, not just html and js ?
Funnily enough, i was loading images with HtmlUnit just this afternoon.
I don't know any way to force HtmlUnit to load all images. However,
loading images is easy enough - you need to get hold of an HtmlImage
element and call its getImageReader method. That returns a
javax.imageio.ImageReader with which you can read the contents of the
image, get its metadata, etc. If you want to go through all the images in
the page, have a crack at:
page.getByXPath("//img");
There might be a more elegant way to do it than that, but i tend to just
use XPath for everything!
tom
--
Tom Anderson | e2x Ltd, 35 New Broad Street, London EC2M 1NH
(e) tom...@e2... | (m) +44 (7960) 989794 | (f) +44 (20) 7194 8016 |