Jsoup select 包含 html 标签的文本

Jsoup select text WITH including html tags

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

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

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

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

我怎样才能让 Jsoup 不遗漏这段文本之间的标签?

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

使用 Element.html() method to get to the html including its inner html tags. You can also use Node.outerHtml() 到 html 包括外部标签。

你的情况:

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

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