无法在特定类(JSOUP)中获取图像Url(由数据原始定义) [英] Cannot fetch image Url (defined with data-original) inside specic class ( JSOUP)

查看:74
本文介绍了无法在特定类(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)]");

然后我雇用(在第二种情况下,它抛出OutOfBoundsException):

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?

推荐答案

最后,感谢

Finally , thanks to 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");
}

这篇关于无法在特定类(JSOUP)中获取图像Url(由数据原始定义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆