Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jsoup exclude children from .text()

Tags:

I have a problem similar to those:

  1. jQuery: exclude children from .text()

Is it possible to achive it in JSoup?

like image 661
emesx Avatar asked Nov 16 '12 21:11

emesx


1 Answers

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());     } } 
like image 154
ShyJ Avatar answered Sep 28 '22 08:09

ShyJ