Jsoup 从 .text() 中排除孩子

Posted

技术标签:

【中文标题】Jsoup 从 .text() 中排除孩子【英文标题】:Jsoup exclude children from .text() 【发布时间】:2012-11-05 15:56:09 【问题描述】:

我有类似的问题:

    jQuery: exclude children from .text()

是否可以在 JSoup 中实现它?

【问题讨论】:

【参考方案1】:

您可能正在寻找电话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());
    

【讨论】:

以上是关于Jsoup 从 .text() 中排除孩子的主要内容,如果未能解决你的问题,请参考以下文章