【问题标题】:Getting the particular (pre-formatted) text (from a website) using JSoup使用 JSoup 获取特定的(预先格式化的)文本(来自网站)
【发布时间】:2019-07-18 14:10:17
【问题描述】:

我是 JSoup 的新手,我想获取写在这个特定 HTML 标记中的文本:

<pre class="cg-msgbody cg-view-msgbody"><span class="cg-msgspan"><span>**the text I want to get is present here, how can I get it using JSoup?**</span></span></pre>

任何帮助将不胜感激。

谢谢!

【问题讨论】:

标签: java html web jsoup


【解决方案1】:
String html = "<pre class=\"cg-msgbody cg-view-msgbody\">"
       + "<span class=\"cg-msgspan\">"
       + "<span>**the text I want to get is present here, "
       + "how can I get it using JSoup?**</span>"
       + "</span>"
       + "</pre>";
    org.jsoup.nodes.Document document = Jsoup.parse(html);

    //a with href
    Element link = document.select("span").last();

    System.out.println("Text: " + link.text());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-21
    相关资源
    最近更新 更多