Anon
Anon

Reputation: 35

Getting the particular (pre-formatted) text (from a website) using JSoup

I'm new to JSoup, and I want to get the text written in this specific HTML tag:

<pre class="cg-msgbody cg-view-msgbody"><span class="cg-msgspan"><span>**the text I want to get is present here, how can I get it using JSoup?**</span></span></pre>

Any help would be appreciated.

Thanks!

Upvotes: 0

Views: 166

Answers (1)

Mthokozisi Khanyile
Mthokozisi Khanyile

Reputation: 21

String html = "<pre class=\"cg-msgbody cg-view-msgbody\">"
       + "<span class=\"cg-msgspan\">"
       + "<span>**the text I want to get is present here, "
       + "how can I get it using JSoup?**</span>"
       + "</span>"
       + "</pre>";
    org.jsoup.nodes.Document document = Jsoup.parse(html);

    //a with href
    Element link = document.select("span").last();

    System.out.println("Text: " + link.text());

Upvotes: 1

Related Questions