如何使用 SelectNodes 排除特定 class?
How to exclude specific class using SelectNodes?
我正在使用 HtmlAgiliyPack
从站点获取 tr 列表。现在 table 上有这些行:
<tr class="group-head">
<tr/>
<tr/>
<tr class="group-head">
<tr/>
我只想得到 tr 而没有 class group-head
我试过:
HtmlNodeCollection rows = doc
.GetElementbyId("page_player_1_block_player_trophies_5")
.SelectNodes("//tr[not(@class, 'group-head')]");
但是这个return:
System.Xml.XPath.XPathException: 'Function 'not' in '//tr[not(@class, 'group-head')]' has an invalid number of arguments.'
如果要检查不等式,请使用
//tr[not(@class='group-head')]
在整个表达式中这是
HtmlNodeCollection rows =
doc.GetElementbyId("page_player_1_block_player_trophies_5")
.SelectNodes("//tr[not(@class='group-head')]");
或者,如果属性值中有多个字符串,使用contains(...)
函数:
//tr[not(contains(@class,'group-head'))]
我正在使用 HtmlAgiliyPack
从站点获取 tr 列表。现在 table 上有这些行:
<tr class="group-head">
<tr/>
<tr/>
<tr class="group-head">
<tr/>
我只想得到 tr 而没有 class group-head
我试过:
HtmlNodeCollection rows = doc
.GetElementbyId("page_player_1_block_player_trophies_5")
.SelectNodes("//tr[not(@class, 'group-head')]");
但是这个return:
System.Xml.XPath.XPathException: 'Function 'not' in '//tr[not(@class, 'group-head')]' has an invalid number of arguments.'
如果要检查不等式,请使用
//tr[not(@class='group-head')]
在整个表达式中这是
HtmlNodeCollection rows =
doc.GetElementbyId("page_player_1_block_player_trophies_5")
.SelectNodes("//tr[not(@class='group-head')]");
或者,如果属性值中有多个字符串,使用contains(...)
函数:
//tr[not(contains(@class,'group-head'))]