Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jsoup select text after tag

Tags:

java

jsoup

I want to extract a text after each tag using jsoup. Is there any way to select it directly or do I have to perform .substring on the whole thing?

<div>
<a href="#"> I don't want this text </a> 
**I want to retrieve this text**
</div>
like image 603
Mintz Avatar asked Apr 25 '13 15:04

Mintz


1 Answers

public static void main(String... args) throws IOException {

    Document document = Jsoup.parse("<div>"
            + "<a href=\"#\"> I don't want this text </a>"
            + "**I want to retrieve this text**" + "</div>");

    Element a = document.select("a").first();

    Node node = a.nextSibling();
    System.out.println(node.toString());
}

Output

**I want to retrieve this text**
like image 144
Vitaly Avatar answered Sep 23 '22 12:09

Vitaly