21

I have a problem similar to those:

  1. jQuery: exclude children from .text()

Is it possible to achive it in JSoup?

Community
  • 1
  • 1
emesx
  • 12,555
  • 10
  • 58
  • 91

1 Answers1

30

You are probably looking for calling 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());
    }
}
ShyJ
  • 4,560
  • 1
  • 19
  • 19