无法在特定的 class 中获取图像 Url(用原始数据定义)(JSOUP)
Cannot fetch image Url (defined with data-original) inside specic class ( JSOUP)
HTML源码(注意是使用了延迟加载jQuery插件):
1).当我 运行 下面的代码从网站获取所有图像网址时:
Elements images=document.select("img[src~=(?i)\.(png|jpe?g|gif)]");
2).但是当我指定 class 时它失败了,如下所示:
Elements images=document.select("div.newscat img[src~=(?i)\.(png|jpe?g|gif)]");
And then I employ ( in second case it throws OutOfBoundsException):
for (int i=0;i<images.size();i++){
imageUrl[i]=images.get(i).attr("src");
}
Could, anyhow, lazy load be problem, if yes, How to solve?
最后感谢android: how can i scrap images (in url ) using jsoup?(Image tag contain attribute "data-original" which is url of image)
我找到了改变
的工作
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");
}
HTML源码(注意是使用了延迟加载jQuery插件):
1).当我 运行 下面的代码从网站获取所有图像网址时:
Elements images=document.select("img[src~=(?i)\.(png|jpe?g|gif)]");
2).但是当我指定 class 时它失败了,如下所示:
Elements images=document.select("div.newscat img[src~=(?i)\.(png|jpe?g|gif)]");
And then I employ ( in second case it throws OutOfBoundsException):
for (int i=0;i<images.size();i++){
imageUrl[i]=images.get(i).attr("src");
}
Could, anyhow, lazy load be problem, if yes, How to solve?
最后感谢android: how can i scrap images (in url ) using jsoup?(Image tag contain attribute "data-original" which is url of image)
我找到了改变
的工作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");
}