jsoup - 如何使用Jsoup提取此图像?

时间:2015-03-04 16:29:52

标签: java android html jsoup

我正在寻找这个div中的主要图像

<div id="imgTagWrapperId" >
<img src ="www.example.com">
</div>

我试过了:

Document document = Jsoup.connect(url).get();

Elements img = document.select("div[id=imgTagWrapperId] img[src]");

String imgSrc = img.attr("src");

我正在使用的网址是http://www.amazon.in/Google-Nexus-D821-16GB-Black/dp/B00GC1J55C/ref=sr_1_1?s=electronics&ie=UTF8&qid=1421161258&sr=1-1&keywords=Google

这对我有用:

 Document document = Jsoup.connect(url).get();

 Element img = document.getElementById("landingImage");

 String imgSrc = img.attr("data-old-hires");

1 个答案:

答案 0 :(得分:2)

Document document = Jsoup.connect(url).get();

Elements img = document.select("img[id=landingImage]");

String imgSrc = img.attr("src");