Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save image from url with HTMLUnit

Tags:

java

htmlunit

Is it possible to save an image to hard disk with HTMLUnit by giving it the image URL? If so how?

Regards!

like image 556
Arya Avatar asked May 19 '12 01:05

Arya


1 Answers

If you're using HtmlUnit then you should have an HtmlPage. There you can get an HtmlImage and save the file this way:

HtmlImage image = page.<HtmlImage>getFirstByXPath("//img[@src='blah']");
File imageFile = new File("/path/to/file.jpg");
image.saveAs(imageFile);

If you do have an URL... then I don't think you need HtmlUnit to download the image.

like image 194
Mosty Mostacho Avatar answered Oct 02 '22 16:10

Mosty Mostacho