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.
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());
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.