문제

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()");
도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top