本文介绍了无法在特定类(JSOUP)中获取图像Url(由数据原始定义)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML源代码(请注意,它使用延迟加载jQuery插件):
HTML source (Note that it uses lazy load jQuery plugin):
1).当我在下面运行代码时,它会从网站获取所有图片Urls:
1). When I run code below it fetches all image Urls from website:
Elements images=document.select("img[src~=(?i)\\.(png|jpe?g|gif)]");
2).但是,当我指定该类时,它将失败,如下所示:
2). But when I specify the class it fails, like below:
Elements images=document.select("div.newscat img[src~=(?i)\\.(png|jpe?g|gif)]");
for (int i=0;i<images.size();i++){
imageUrl[i]=images.get(i).attr("src");
}
推荐答案
Elements images=document.select("div.newscat img[src~=(?i)\\.(png|jpe?g|gif)]");
for (int i=0;i<images.size();i++){
imageUrl[i]=images.get(i).attr("src");
}
Elements images=document.select("div.newscat").select("img");
for (int i=0;i<images.size();i++){
imageUrl[i]=images.get(i).attr("data-original");
}
这篇关于无法在特定类(JSOUP)中获取图像Url(由数据原始定义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!