【问题标题】:jsoup - How to extract this image using Jsoup?jsoup - 如何使用 Jsoup 提取此图像?
【发布时间】:2015-03-06 00:22:14
【问题描述】:

我正在寻找这个 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");

我正在使用的 URL 是 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");

【问题讨论】:

    标签: java android html jsoup


    【解决方案1】:
    Document document = Jsoup.connect(url).get();
    
    Elements img = document.select("img[id=landingImage]");
    
    String imgSrc = img.attr("src");
    

    【讨论】:

    • 谢谢!你的回答帮助了我。我没有首先找到 id="landingImage" 。这对我有用: Document document = Jsoup.connect(url).get();元素 img = document.getElementById("landingImage"); String imgSrc = img.attr("data-old-hires");
    猜你喜欢
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2017-09-14
    • 1970-01-01
    相关资源
    最近更新 更多