Search code examples
javaimagehtmlunit

How to convert an <img... in html to byte [] in Java


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.


Solution

  • 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.