Reputation: 44998
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.
Upvotes: 5
Views: 6291
Reputation: 186
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());
Upvotes: 15
Reputation: 12729
As you have tagged the question "xpath", I am going to assume that you will accept an XPATH solution. In the absence of information to the contrary, I will make some reasonable assumptions. Please let us know if you want to correct or refine these assumptions.
The following XPATH expression...
//span[.='Party Date:'][1]/following-sibling::text()
...returns...
' 14.08.2012'
Note: This works in both XPATH 1.0 and XPATH 2.0
Upvotes: 1