希望有人能迅速为我指明正确的方向,解决我的 XPath 问题。
目前我已经到了在我的 HTML 源代码中识别我需要的正确表格的地步,但是我需要只处理 DOM 中某处具有文本“Chapter”的行。
我最后的尝试是这样做:
// get the correct table
HtmlTable table = page.getFirstByXPath("//table[2]");
// now the failing bit....
def rows = table.getByXPath("*/td[contains(text(),'Chapter')]")
我认为上面的 xpath 将代表所有具有“td”子元素的元素,该子元素在其 dom 中某处包含文本“Chapter”
来 self 的来源的匹配行的示例是:
<tr valign="top">
<td nowrap="" align="Right">
<font face="Verdana">
<a href="index.cfm?a=1">Chapter 1</a>
</font>
</td>
<td class="ChapterT">
<font face="Verdana">DEFINITIONS</font>
</td>
<td> </td>
</tr>
非常感谢任何帮助/指点。
谢谢,
最佳答案
使用这个 XPath:
//td[contains(., 'Chapter')]
关于xml - XPath 定位具有特定文本解析 HTML 表格的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9643762/