java – Jsoup从.text()中排除小孩

前端之家收集整理的这篇文章主要介绍了java – Jsoup从.text()中排除小孩前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个类似于以下的问题:

> 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());
    }
}
原文链接:https://www.f2er.com/java/126117.html

猜你在找的Java相关文章