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

标签 java html web jsoup

我是 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>

如有任何帮助,我们将不胜感激。

谢谢!

最佳答案

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

关于java - 使用 JSoup 获取特定的(预先格式化的)文本(从网站),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54861688/

相关文章:

html - 表单标签的 CSS 样式

java - AI 如何为战舰建模遗传编程

python - 如何正确安装Open edX电子商务服务?

java - 在 Java 中使子类中的变量可变

jquery - 跨度占据整行

javascript - 图片未在 chrome 中加载

html - 将图像添加到 Bootstrap 选择?

web - 如何测量我网站客户端的图像下载时间?

java - Lucene:基于字典术语索引文档/实现自定义分析器

Java编译器: Is it possible to feed in variables on run