如何使用SelectNodes排除特定类?

时间:2018-05-05 19:12:09

标签: c# xpath html-agility-pack

我使用HtmlAgiliyPack从网站上获取tr列表。现在在那张桌子上有这些行:

<tr class="group-head">
<tr/>
<tr/>
<tr class="group-head">
<tr/>

我想只获得没有我尝试过的课程group-head的tr:

HtmlNodeCollection rows = doc
           .GetElementbyId("page_player_1_block_player_trophies_5")
            .SelectNodes("//tr[not(@class, 'group-head')]");

但这回归:

  

System.Xml.XPath.XPathException:&#39;功能&#39;不是&#39; in&#39; // tr [not(@class,&#39; group-head&#39;)]&#39;参数数量无效。&#39;

1 个答案:

答案 0 :(得分:0)

如果您想检查不平等,请使用

//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'))]
相关问题