Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get img src with jsoup

Tags:

android

jsoup

This is my html

<script src="/ClientScripts/swfobject.js" language="javascript" type="text/javascript"> </script>
<div class="contentDetails">
<div id="ctl00_MainContentPlaceHolder_ContentDetailsBodyDivision" class="body">
<div align="justify">

<p align="center"><img width="500" height="352" alt="MVM315" src="/UserUpload/Image/1(825).jpg" /></p>
<p align="center"><img width="500" height="352" alt="MVM315" src="/UserUpload/Image/2(598).jpg" /></p>

How can i get {src="/UserUpload/Image/1(825).jpg"} with jsoup ?

I have this code but not working

Document doc = Jsoup.parse(html);
Elements mElements = doc.select("div[id^=ctl00_MainContentPlaceHolder_ContentDetailsBodyDivision]");
Result = mElements.get(0).tagName("img").toString();
like image 746
user3453159 Avatar asked Dec 20 '22 11:12

user3453159


1 Answers

try this:

 Element imageElement = document.select("img").first();

 String absoluteUrl = imageElement.absUrl("src");  //absolute URL on src

 String srcValue = imageElement.attr("src");  // exact content value of the attribute.

More info here: http://jsoup.org/cookbook/extracting-data/working-with-urls

like image 84
Alécio Carvalho Avatar answered Jan 09 '23 22:01

Alécio Carvalho