【发布时间】:2016-05-17 19:40:16
【问题描述】:
我想使用 jsoup HTML 解析器库从 div 元素中提取 HTML 代码。
HTML 代码:
<div class="entry-content">
<div class="entry-body">
<p><strong>Text 1</strong></p>
<p><strong> <a class="asset-img-link" href="http://example.com" style="display: inline;"><img alt="IMG_7519" class="asset asset-image at-xid-6a00d8341c648253ef01b7c8114e72970b img-responsive" src="http://example.com" style="width: 500px;" title="IMG_7519" /></a><br /></strong></p>
<p><em>Text 2</em> </p>
</div>
</div>
提取部分:
String content = ... the content of the HTML from above
Document doc = Jsoup.parse(content);
Element el = doc.select("div.entry-body").first();
我希望结果 el.html() 是来自 div 选项卡 entry-body 的整个 HTML:
<p><strong>Text 1</strong></p>
<p><strong> <a class="asset-img-link" href="http://example.com" style="display: inline;"><img alt="IMG_7519" class="asset asset-image at-xid-6a00d8341c648253ef01b7c8114e72970b img-responsive" src="http://example.com" style="width: 500px;" title="IMG_7519" /></a><br /></strong></p>
<p><em>Text 2</em> </p>
但我只得到第一个<p> 标签:
<p><strong>Text 1</strong></p>
【问题讨论】:
-
这个问题对我来说是不可重现的。如果我完全按照你所说的那样做,我会得到所有内部 HTML 就好了。您使用的是哪个版本的 JSoup?我的检查是用 1.8.3 版完成的
-
我也在使用 1.8.3 - 最后一个版本,但它不起作用...你得到了整个
div内容的结果?
标签: android html-parsing jsoup