我有一个带有表格的 xhtml 页面。通常,其中一个在单元格中有文本"针文本"。如何获得这样的所有桌子?
<table class="content_table">
<tr>
<td>Column 1</td>
<td>Column 2</td>
</tr>
<tr>
<td>Value 11</td>
<td>Value 21</td></tr>
<tr>
<td><a href="link.html">needle text</a></td>
<td>Value 22</td>
</tr>
</table>
注意:表格可以带有标签:thead,th等。
- 从 xhtml 页面收集所有表 - 用
"//*[@class='content_table']"
完成。 - 找到带有文本的节点,但没有成功。我试过
//alink[text() = "needle text"]
但得到空的结果。 - 在父树的父树的父级中查找表作为祖先。
//alink[text() = "needle text"]/..
你可以试试下面的 XPATH
//a[.='needle text']/ancestor::table[1][@class='content_table']
或
//table[@class='content_table' and .//a[.='needle text']]