【发布时间】:2012-05-13 09:37:29
【问题描述】:
对没有name 或id 生成的表行使用HtmlAgilityPack。相反,我需要根据行的 bgcolor 属性中包含的值进行选择:
我了解 XPath 将返回 name 属性 = display 的所有行:
foreach(HtmlNode cell in doc.DocumentElement.SelectNodes("//tr[@name='display']/td")
给定下面的代码sn-p,当行的bgcolor ="#FFFFFF"> 时,什么表达式会选择所有元素?
我试过了:SelectNodes(//tr[@bgcolor='#FFFFFF']/td")
> <tr bgcolor="#EAF2FA">
> <td colspan="2">
> <font style="font-family: sans-serif; font-size:12px;"><strong>Name</strong></font>
> </td> </tr> <tr bgcolor="#FFFFFF">
> <td width="20"> </td>
> <td>
> <font style="font-family: sans-serif; font-size:12px;">Steve</font>
> </td> </tr>
谢谢
【问题讨论】:
-
xpath 很适合我。我看不出它为什么不工作的理由。你能多显示一点代码吗?
-
我发现当我使用完整格式的 HTML 文档时,我的代码确实匹配。感谢您指出我的工作方向是正确的。