使用JSoup提取图像src

Joh*_*ket 4 jsoup

我试图使用jsoup从这个网页中提取所有图像网址?任何人都可以提供如何做的帮助吗?所有标签的格式都是这样的,但我只需要src图像,而不是ajaxsrc:

<IMG ajaxsrc="/pics32/160/MP/MPYXBXTSYVKAKJQ.20110918032436.jpg" src="http://image.cdnllnwnl.xosnetwork.com/pics32/160/MP/MPYXBXTSYVKAKJQ.20110918032436.jpg">
Run Code Online (Sandbox Code Playgroud)

这是链接:http://www.ncataggies.com/PhotoAlbum.dbml? DB_OEM_ID = 24500& PALID = 417884

这是格式吗?

        Document doc = null;
    try {
        doc = Jsoup.connect(articleLink).timeout(10000).get(); 
    } catch (IOException ioe) {
        return null;
    }
    Element content = doc.getElementById("div.thumb-image preview");
    Elements links = content.getElementsByAttribute("IMG");
    for (Element link : links) {
      String source = link.attr("src");
      Elements imageLinks = link.getElementsByAttribute(source);
      for(Element imageLink: imageLinks){
          //imageLink = picture link?
      }

}
Run Code Online (Sandbox Code Playgroud)

这似乎不是它.我的代码中有打印语句,它们没有受到影响.

小智 14

您应该可以执行以下操作来获取所有img标记:

for (Element e : doc.select("img")) {
    System.out.println(e.attr("src"));
}
Run Code Online (Sandbox Code Playgroud)

这应该选择所有img标签,然后获取src属性并打印到控制台.


Ped*_*ena 1

假设您已经拥有根据此 IMG 的元素,请尝试以下操作:

字符串源 = img.attr("src");

该attr方法继承自Node类

华泰