Simon Mourier's Avatar
Simon Mourier's blog (1807 answers on StackOverflow) about Microsoft technologies C#, C/C++, .NET, WinRT, WinUI3, AOT, P/Invoke, COM, Interop, DirectX, Direct2D, Windows, ...
  • 🔎︎ Search
  • Categories
  • Archives
  • About Me
  • c#
  • html
  • html-agility-pack

How to get the count of tables in an html file with C# and html-agility-pack

Apr 27, 2013 See the question and my original answer on StackOverflow

Something like this:

HtmlDocument doc = new HtmlDocument();
doc.Load(myTestFile);

// get all TABLE elements recursively
int count = doc.DocumentNode.SelectNodes("//table").Count;

// output to a text file
File.WriteAllText("output.txt", count.ToString());
  • SmoBlog © 2010-2026 Simon Mourier. All rights reserved.
  • Privacy & Terms