Rudziankoŭ
Rudziankoŭ

Reputation: 11251

How do correctly get String link from HtmlImage Object in Java?

I try in such way:

HtmlPage currentPage = (HtmlPage) webClient.getPage((urlList.get(i).toString()));

And have:

java.net.MalformedURLException: no protocol: HtmlImage[<img src="http://media.animewallpapers.com/wallpapers/misc/misc_164_t.jpg?m=21312126359&quot;"

What is a correct way?

Upvotes: 0

Views: 162

Answers (1)

Mosty Mostacho
Mosty Mostacho

Reputation: 43434

In order to get the src attribute from an image you need to use the getSrcAttribute() method. Suppose myImage is an HtmlImage object, this code would output the src attribute to the console:

System.out.println(myImage.getSrcAttribute());

As a side note, casting an image as an HtmlPage will most likely throw an exception.

Upvotes: 1

Related Questions