xml - XPath 定位具有特定文本解析 HTML 表格的单元格

标签 xml xslt xpath groovy htmlunit

希望有人能迅速为我指明正确的方向,解决我的 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>&nbsp;</td>
</tr>

非常感谢任何帮助/指点。

谢谢,

最佳答案

使用这个 XPath:

//td[contains(., 'Chapter')]

关于xml - XPath 定位具有特定文本解析 HTML 表格的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9643762/

相关文章:

java - XMLGregorianCalendar 日期比较

xslt - 如何格式化xslt中的日期?

javascript - xpath 评估多个元素值

xml - 使用 xslt 遍历属性

xml - 通过 Powershell 的 SOAP 语法

java - 如何通过 xsd 验证 org.w3.dom.Document?

android - 我怎样才能获得 MAC 地址 android 7.0

java - 解析 XML 并在不绑定(bind)命名空间的情况下获取 DOM 树 - Java

.net - DotNet 2.0 或 3.5、IE、XSL 和 XSL-FO 功能是什么?

xpath - Selenium 找不到元素