繁体   English   中英

通过JSOUP解析时不希望创建文档结构

[英]Don't want the document structure to be created while parsing through JSOUP

我正在使用Jsoup API使用Jsoup.parse()方法来解析HTML的一部分。 但是,在解析时会将文档结构添加到HTML内容中。

例如:

<p><a href="some link">some link data</a> Some paragraph content</p>

成为

<html>
<head></head>
<body>
<p><a href="some link">some link data</a> Some paragraph content</p>
</body>
</html>

解析后,我不需要文档结构(我不需要html,head,body标签)。 有什么办法吗? 提前致谢。

我使用了Document的body()和html()方法

Document storyBodyDoc;
storyBodyDoc = Jsoup.parse(body);
storyBodyDoc.body().html()

谢谢你的建议。

您可以选择身体元素的孩子:

Document doc = Jsoup.parse("<p><a href=\"some link\">some link data</a> Some paragraph content</p>");
Elements content = doc.body().children();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM