javahtmlparsingjsoup

How to get this value using Jsoup?


This is the snippet from the page:

<br><b>Price:</b>&nbsp;Rs. 24,900.00&nbsp;<br>

I need to get the value Rs.24,900.00. But I'm not sure how to get it, since it is not enclosed by any element.

I used this: doc.select("b:contains(Price:)"); to get to the Price: element.

But how would I get that Rs.24,900.00 value?


Solution

  • Document doc = Jsoup.parse( "<br><b>Price:</b> &nbsp; Rs. 24,900.00 &nbsp; <br>");
    
    Element el = doc.select("b").first(); //get the element which contains "Price:"
    
    String text = ((TextNode) el.nextSibling()).text();
    

    Here, first I have to obtain the element which contains Price:. Then we can get it's nextsibling and use text() method to get its text.

    Thanks to user1121883 for his answer on similar question.