简体   繁体   English

使用JSoup获取特定的(预格式化的)文本(从网站)

[英]Getting the particular (pre-formatted) text (from a website) using JSoup

I'm new to JSoup, and I want to get the text written in this specific HTML tag: 我是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>

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks! 谢谢!

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());

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

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