开发者

Calling getByXPath on DomNode with HtmlUnit

I've extracted a List of DomNode objects from the HTMLPage object using getByXPath. However, when I try and query a returne开发者_Go百科d DomNode object, again using getByXPath, the results are as if I queried the HTMLPage object.

final WebClient webClient = new WebClient();
HTMLPage page = (HtmlPage) webClient.getPage("http://test.page.com");

final List<HtmlTableCell> cells = (List<HtmlTableCell>) page.getByXPath("//td[@width='85%']");

// Number of cells: 16
logger.debug("Number of cells: " + cells.size());

HtmlTableCell cell = cells.get(0);
final List<HtmlTableCell> childCells = (List<HtmlTableCell>) cell.getByXPath("//td[@width='85%']");

// Number of cells: 16
logger.debug("Number of cells: " + childCells.size());


//td in XPath means Select all td elements no matter where they are in the document. See http://www.w3schools.com/xpath/xpath_syntax.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜