【问题标题】:Jsoup select text WITH including html tagsJsoup选择包含html标签的文本
【发布时间】:2015-06-20 17:30:41
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: java android html textview jsoup


    【解决方案1】:

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

    使用Element.html() 方法获取包含其内部html 标记的html。您也可以在包含外部标签的 html 中使用Node.outerHtml()

    在你的情况下:

    Document doc = Jsoup.parse(response, "UTF-8");
    
    Element elMotD = doc.select("td.info").first();
    String motdHtml = elMotD.html();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      • 2016-10-25
      • 1970-01-01
      • 2023-03-16
      • 2017-06-04
      相关资源
      最近更新 更多