java - Jsoup 从 .text() 中排除 child

标签 java css-selectors jsoup

我有类似的问题:

  1. jQuery: exclude children from .text()

是否可以在 JSoup 中实现它?

最佳答案

您可能正在寻找调用 ownText :

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class Main {
    public static void main(String[] args) throws Exception {
        final Document document = Jsoup.parse("<html><head/><body><a href=\"#\" class=\"artist\">Soulive<span class=\"create-play\">Play</span></a></body></html>");
        final Element elem = document.getElementsByAttributeValue("class", "artist").first();
        System.out.println(elem.ownText());
    }
}

关于java - Jsoup 从 .text() 中排除 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13424816/

相关文章:

java - 通过 jython 在 java 类中使用 jar

javascript - 如何在 .html 模板 Angular 中的 div 上定义多种样式

java - 从 src 属性(url)中提取图像名称

android - 在 Android 上动态添加 imageViews

java - jboss logmanager 通过转义引号从 log4j2 中破坏我的应用程序 json-logs 的 json 格式

java - ExecutorService vs Casual Thread Spawner

java - 支柱 2 : how to send JSON to action

css - 第一个 child + 不是选择器?

css - IE9 是否支持 CSS3::before 和::after 伪元素?

java - 如何在 JSOUP 中获取显示/视觉图像大小(而不是实际图像大小)?