2

我正在尝试使用 HAP 访问带有前缀的标签,但以下内容不起作用(它们不返回任何内容):

HtmlAgilityPack.HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//*[name() ='sc:xslfile']");
HtmlAgilityPack.HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//*['sc:xslfile']");

有什么想法吗?

编辑:

HTML 看起来像这样: <p>Men's Standings<br /> <sc:xslfile runat="server" datasource="/Global/Tables/1_01/9859_" id="WC_9859"></sc:xslfile> <br /><br /><br /> Women's Standings <br /><sc:xslfile runat="server" datasource="/Global/Tables/1_01/9860_" id="WC_9860"></sc:xslfile></p>

@Pat,我尝试了starts-with,但仍然不行。

也许是因为标签是空的?

4

1 回答 1

2

您也许可以使用starts-with 选择器。

IE:

var nodes = document.DocumentNode.SelectNodes("//*[starts-with(@class, 'cnn_')]");

其中@class 是您要查找的属性。

更新:

如果您只对数据源和/或 id 感兴趣,您可以运行:

//*[@datasource]

或者

//*[contains(@id, 'WC_']

但是,了解您要提取的内容将有助于改进选择器。

于 2010-01-20T22:36:19.313 回答