Reputation: 9023
I want to get image name and its image URL. My html is like this:
<td class="text-center">
<a href="MYLINK.html">
<img src="IMAGE INK.jpg" alt="IMAGE NAME" title="MY TITILE" class="img-thumbnail" />
</a>
</td>
How can I do this?
Upvotes: 0
Views: 756
Reputation: 106
This is the way that I did it.
String html_to_parse = "<td class=\"text-center\"><a href=\"MYLINK.html\"><img src=\"IMAGE INK.jpg\" alt=\"IMAGE NAME\" title=\"MY TITILE\" class=\"img-thumbnail\" /></a></td>";
Document doc = Jsoup.parse(html_to_parse);
String imageUrl = doc.select("img").attr("src");
String imageName = doc.select("img").attr("title");
Upvotes: 0
Reputation: 9023
i done it by
Element e4 = row.select("td.text-center > a > img").first();
String URL = e4.attr("src");
String TITLE = e4.attr("title");
System.out.println("URL = " + URL);
System.out.println("TITLE = " + TITLE);
Upvotes: 1
Reputation: 2904
String your_html = "<td class=\"text-center\"><a href=\"MYLINK.html\"><img src=\"IMAGE INK.jpg\" alt=\"IMAGE NAME\" title=\"MY TITILE\" class=\"img-thumbnail\" /></a></td>";
Document document = Jsoup.parseBodyFragment(html);
Element element = document.body();
Element link = element.select("img.img-thumbnail").first(); // Img with class img-thumbnail
System.out.println(link.attr("src")); //The attribute, 'src' , within the selected img tag
Hope this helps :)
Upvotes: 1
Reputation: 6547
Once you have the image element, e.g.:
Element image = document.select("img").first();
String url = image.attr("abs:src");
String name = image.attr("abs:title");
or try playing also with and see what info you want:
.attr("src")
.attr("title")
Upvotes: 2