ogsMC
ogsMC

Reputation: 33

how to skip table using HtmlAgilityPack

i wrote an app that take values from a table and manipulat them, my problem is that there is 2 tables before the table i want(without id,class) . i want to skip them and go to the third table . my code:

        HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table");
        HtmlNodeCollection rows = tables[2].SelectNodes(".//tr");

        foreach (HtmlNode item in rows)
        {    
         /// my code//

        }  

i thought the code: table[2] means go to the third table but infact it mean take 3 tables, is there a way to define spacific table or from to tables? (without id or class name in the table)

Upvotes: 0

Views: 442

Answers (2)

Pandian
Pandian

Reputation: 9126

i think the below code will help you on this...

HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table[3]");
HtmlNodeCollection rows = tables.SelectNodes(".//tr");

"//table[3]" : it defines the 3rd table

Upvotes: 1

André Scartezini
André Scartezini

Reputation: 236

You just need to specify the index of the table: HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table[2]");

Upvotes: 0

Related Questions