Tell me, please, how can I get text() only from a parent, not including children? Example:

 <p> <img>100x100</img> вот такая картинка </р> 

If you select the tag <р> and call the text() method, then it will output 100х100 вот такая картинка , but I just need вот такая картинка .

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

Just remove the unnecessary tag:

 Element p = ...; p.remove(p.getElementsByTagName("img").first()); System.out.println(p.text()); 

The code did not check, the methods may be slightly different.

    Use Element.ownText()