Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jSoup to find a node with some particular text

Tags:

java

xpath

jsoup

How can I find this snippet of HTML in a node using jSoup:

<span style="font-weight: bold">Party Date:</span> 14.08.2012<br>

I'd like to extract the date from the HTML snippet. The problem is that this snippet of HTML can occur anywhere within an Element so I need to match it using the contained text.

like image 803
Mridang Agarwalla Avatar asked Aug 15 '12 09:08

Mridang Agarwalla


1 Answers

If you are still looking for jsoup selector query.. this works for me..

    String html = "<span style=\"font-weight: bold\">Party Date:</span> 14.08.2012<br>";

    System.out.println("Date " + Jsoup.parse(html).select("span:matchesOwn(Party Date:)").first().nextSibling().toString());
like image 180
Kunjal Shah Avatar answered Sep 30 '22 20:09

Kunjal Shah