这是我的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>
如何使用jsoup获取{src="/UserUpload/Image/1(825).jpg"
}?
我有这段代码但没有工作
Document doc = Jsoup.parse(html);
Elements mElements = doc.select("div[id^=ctl00_MainContentPlaceHolder_ContentDetailsBodyDivision]");
Result = mElements.get(0).tagName("img").toString();
答案 0 :(得分:7)
试试这个:
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.
此处有更多信息:http://jsoup.org/cookbook/extracting-data/working-with-urls
答案 1 :(得分:0)
怎么样:
Element img = document.select("img").first()
String src = img.attr("src");
有关详细信息,请参阅:http://jsoup.org/cookbook/extracting-data/attributes-text-html