繁体   English   中英

Jsoup选择包含html标签的文本

[英]Jsoup select text WITH including html tags

我使用 Jsoup 在<td></td>标签之间选择一些代码。 它看起来像这样:

Document doc = Jsoup.parse(response, "UTF-8");

Element elMotD = doc.select("td.info").first();
String motdText = elMotD.text();

我现在的问题是 jsoup 选择了我想要的文本,但它只是整理了像<br>这样的标签<br>这些标签对于我以后在 Android TextView 中的显示很重要。

我怎样才能做到这一点 Jsoup 不会错过这段文本之间的标签?

见这里: http : //jsoup.org/cookbook/extracting-data/attributes-text-html

使用Element.html()方法获取 html,包括其内部 html 标签。 您还可以将Node.outerHtml()用于包含外部标签的 html。

在你的情况下:

Document doc = Jsoup.parse(response, "UTF-8");

Element elMotD = doc.select("td.info").first();
String motdHtml = elMotD.html();

暂无
暂无

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

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