/ / Jsoup schließt Kinder von .text () aus - Java, CSS-Selektoren, Jsoup

Jsoup schließt Kinder von .text () aus - java, css-selectors, jsoup

Ich habe ein ähnliches Problem:

  1. jQuery: Kinder von .text () ausschließen

Ist es möglich, dies in JSoup zu erreichen?

Antworten:

19 für die Antwort № 1

Sie suchen wahrscheinlich nach einem Anruf 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());
}
}