views:

144

answers:

1

I have opened a webpage in HtmlUnit headless browser. Now that webpage contains a image html tag as follows:

<img src="..." />

So I want that image only. But the problem is that the same src URL of the image shows diff. image each time. Means, if we refresh the img src URL, then it shows diff. image each time.

So how to get the image that is displayed on the html page.

+1  A: 

When you get the HTMLPage, you have to get the image through one of its method. You can then get an HtmlImage, which can be saved as a file. You'll just have to analyse this file later.

Valentin Rocher
Oh... yes... There is a method "saveAs()" in HtmlImage class....Can I convert that HtmlImage directly into byte[] or I have to first save it and then convert the saved file into byte[]?
Yatendra Goel
could you please look at the question at http://stackoverflow.com/questions/2131049/problem-in-htmlunit-api-for-java-headless-browser
Yatendra Goel
You can use `getWebResponse` and get the content as byte[]
Valentin Rocher