Search code examples
c#html-agility-pack

How to get specific rows?


Suppose I have the following situation:

<table>
   <tbody>
      <tr class="dark center"></tr>
      <tr class="odd deactivate"></tr>
      <tr class="deactivate"></tr>
      <tr class="odd deativate"></tr>
      <tr class="dark center"></tr>
   </tbody>
</table>

is there a way to exclude from the result the tr with class dark center?

Actually I used this: var rows = doc.documentNode.SelectNodes(".//table//tbody//tr");


Solution

  • You can use not-contains:

    doc.documentNode.SelectNodes(".//table//tbody//tr[not(contains(@class, 'dark center'))]")