views:

135

answers:

2

How can we find how many columns and rows are there in the html file ? How can we count that how many td tags are there in the html file ?

+3  A: 

Use the HTML Agility pack to parse the HTML, then query it for the number of <TR> tags for the number of rows in a table.

For the <TD>, use the first row and get the number of those. Check if there are any colspan attributes and add the value of each - 1, to get the number of columns in the table.

For example, to get the number of rows:

HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");

// Assuming only one table in the file
int colums = doc.DocumentElement.SelectNodes("//tr").Count();
Oded
How do I extract the content from html table using HTML Agility pack,what type of code I should write to extract the content column by column from html table ?
Harikrishna
A: 

There isn't a way in HTML to count the <TD> rows/columns I'm afraid. You're best bet would be to get a program like Notepad++ and literally "search" for <TD and see how many results appear. Or you could go down the Javascript route - but that's a different kettle of fish ;)

Neurofluxation
OP is using C# and .NET, not asking about how to do so in HTML. It's a little vague, but it's in the tags.
D_N
Apologies, been a long week!
Neurofluxation