(HtmlAgilitypack)Error in SelectNode

Topics: Developer Forum
Jan 2, 2010 at 10:57 AM

Hi All,

I need to crawl this website whereby i need to get all the cell contents.

The Url of the website that I want to crawl : http://www.dartmouth.edu/~floods/MasterList.htm

I'm able to get the content but the number of "count" doesn't seem accurate.

According to the website, there are 2 tables.

But I want to crawl the first table ,hence i write this:

HtmlNodeCollection table = html.DocumentNode.SelectNodes("//table[1]");

After that, I want to get the data from each cell of each row from the table.So i wrote this:

 foreach (HtmlNode row in table[1].SelectNodes("//tr"))
 {
      foreach (HtmlNode cell in row.SelectNodes("//td/font/text()"))
     {
            Console.WriteLine("cell: " + cell.InnerText);
      }
}
Suppose there are 30 Columns per row.And 80 rows per table. But when I'm debugging,it shows me the number of counter of inner foreach loop is total of row*column in a row..I'm really have no idea how it calculates the counter.

(Suppose a row will have 30 columns/cells.But the number of counter shows that it counts row*column in a row.)(The inner foreach loop counter is already 2k plus,but the number should be 30).

 

I hope you guys understand my problem.Is it the way I code got problem?or the selectnode got bug?

Please help.

 

Thank you.

 

IM:cassgks_87@hotmail.com