我使用getByXPath从HTMLPage对象中提取了一个DomNode对象列表。但是,当我尝试查询返回的DomNode对象时,再次使用getByXPath,结果就好像我查询了HTMLPage对象。
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());
答案 0 :(得分:1)
//td
表示选择所有td元素,无论它们在文档中的位置。见http://www.w3schools.com/xpath/xpath_syntax.asp