样式属性未使用jsoup显示 [英] style attribute not being displayed using jsoup

查看:69
本文介绍了样式属性未使用jsoup显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jsoup仅通过首页链接从在线漫画网站中获取特定漫画章节的所有图片.

I am using Jsoup to fetch all images of a particular manga chapter from online-manga sites using only the first page link.

我已成功检索首页的总页数和源代码,例如 :如果提供了此链接"

I have successfully retrieved the total page number and the src of the first page, for example: if supplied with this link "http://www.mangapanda.com/feng-shen-ji/1/1" the output will be:

总页数:49

标题:封神记1

ImageURL: http://i15 .mangapanda.com/feng-shen-ji/1/feng-shen-ji-2974919.jpg

ImageURL : http://i15.mangapanda.com/feng-shen-ji/1/feng-shen-ji-2974919.jpg

我现在要做的是获取第二页的src,然后自动递增以获取其余的内容.指向第二页的链接在html中为:

what I want to do now is to fetch the src of the second page and then auto-increment to get the rest. The link to the second page is in the html as:

<div id="prefetchimg" style="background-image: url("http://i34.mangapanda.com/feng-shen-ji/1/feng-shen-ji-2974921.jpg");"></div>

但是当我使用jsoup作为

but when I use jsoup as

String url = "http://www.mangapanda.com/feng-shen-ji/1";
Document doc = Jsoup.connect(url).userAgent("Mozilla").get();
Elements div = doc.select("div");
for (Element divParse : div) {
if(divParse.id().equals("prefetchimg"))
System.out.println(divParse);}

我只能得到

<div id="prefetchimg"></div>

代替

<div id="prefetchimg" style="background-image: url("http://i34.mangapanda.com/feng-shen-ji/1/feng-shen-ji-2974921.jpg");"></div>

如何获取样式属性?

How do I get the style attribute?

推荐答案

@eltabo

好吧,在您的情况下,您的标记已被javascript函数修改,因此Jsoup无法看到此属性

Ok, in your case, your tag has been modified by a javascript function, so Jsoup can't see this attribut

这是真的,JSoup仅适用于HTML页面.对于带有JS的HTML,例如使用 HtmlUnit

And this is true, JSoup is for Html page only. For Html with JS use for example HtmlUnit

这篇关于样式属性未使用jsoup显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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