Question

What XPath expression should I use to parse Google XHTML results page? I'm not able to retrieve it using

XPathExpression expr = xpath.compile(".//li[@class='g']/div/h3/em/text()");
Was it helpful?

Solution

If it's XHTML, you probably need a namespace binding on the expression

Namspace ns = NAmespave.getNamespace("x", "http://www.w3.org/1999/xhtml");
XPathExpression expr = xpath.compile(
    ".//x:li[@class='g']/x:div/x:h3/x:em/text()", null, null, ns);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top