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

我有类似的问题:

  1. jQuery: exclude children from .text()

是否可以在 JSoup 中实现它?

【问题讨论】:

    标签: java css-selectors 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());
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-16
      • 2013-01-08
      • 1970-01-01
      • 2012-07-06
      • 2017-02-12
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多