【问题标题】:Jsoup - getting src value of img from websiteJsoup - 从网站获取 img 的 src 值
【发布时间】:2015-06-25 23:11:10
【问题描述】:

我正在尝试使用 Jsoup 从网站获取 img 元素的 src 值。其他一切正常(从图像中获取其他值),但没有获取元素的 src 值。

我使用的代码:

org.jsoup.nodes.Document doc = Jsoup.connect("url").timeout(10000).get();
Element img = doc.getElementById("image_id");
String src = img.attr("src");
Log.v(MainActivity.TAG, src);

作为回报,我有奇怪的日志而不是 URL。

在三星 GT9515 上:

06-26 00:54:38.787  18713-18793/? V/My_App﹕ [ 06-26 00:54:38.787   272:  272 D/SurfaceFlinger ]
FPS : 59.92

在 Nexus 5 模拟器上:

06-25 19:01:08.027    2329-2373/? V/My_App﹕ [ 06-25 19:01:09.671  1596: 1596 I/auditd   ]
type=1400 audit(0.0:4eni avc:  denied  { 0x10 } for  cor_7"Binder_7" capability=36  scontext=u:r:system_servext=u tcontext=u:r:system_server:s0 tclass=capability2

正如我之前所说,它适用于图像的其他属性 - 宽度、高度、abs:src...

你知道故障的原因是什么吗?

谢谢!

【问题讨论】:

  • 我好像无法获取图片的src属性,因为它是在网站上执行脚本后设置的。我的问题的解决方案是从脚本中解析参数,然后使用该参数构建一个包含地址的 URI。

标签: android android-studio jsoup


【解决方案1】:

这对我有用:

doc = Jsoup.connect(url).get();
Elements container = doc.select("div[class=\"image-banner\"]");
Element e = container.select("img").get(0);
System.out.println(e.attr("src"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-28
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多