使用JSoup提取图像src [英] Extract image src using JSoup
本文介绍了使用JSoup提取图像src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用jsoup提取此网页中的所有图像url吗?谁能提供有关如何做的帮助?所有标签的格式都这样,但我只需要src图像,而不需要ajaxsrc:
I am trying to extract all the image url's from this webpage using jsoup? Can anyone offer help on how to do it? All the tags are formatted like this, but I only need the src image, not the ajaxsrc:
<IMG ajaxsrc="/pics32/160/MP/MPYXBXTSYVKAKJQ.20110918032436.jpg" src="http://image.cdnllnwnl.xosnetwork.com/pics32/160/MP/MPYXBXTSYVKAKJQ.20110918032436.jpg">
这里是链接: http://www.ncataggies.com/PhotoAlbum.dbml?DB_OEM_ID=24500& ; PALBID = 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?
}
}
似乎并非如此.我的代码中有打印语句,但没有被击中.
That doesn't seem to be it. I have print statements in my code, and they aren't getting hit.
推荐答案
您应该能够执行以下操作来获取所有img标签:
You should be able to do something like this to get all img tags:
for (Element e : doc.select("img")) {
System.out.println(e.attr("src"));
}
这应该选择所有img标签,然后获取src属性并打印到控制台.
This should select all img tags and then grab the src attribute and print to the console.
这篇关于使用JSoup提取图像src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文