Get img src using 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"

} using jsoup?

I have this code but doesn't work

Document doc = Jsoup.parse(html);
Elements mElements = doc.select("div[id^=ctl00_MainContentPlaceHolder_ContentDetailsBodyDivision]");
Result = mElements.get(0).tagName("img").toString();

      

+3


source to share


2 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

+7


source


What about:

Element img = document.select("img").first()
String src = img.attr("src");

      



For more information see this: http://jsoup.org/cookbook/extracting-data/attributes-text-html

0


source







All Articles