C# HtmlAgilityPack Select table from specific h2

Brennun

New Member
I have some html:\[code\]<h2>Results</h2> <div class="box"> <table class="tFormat"> <th>Head</th> <tr>1</tr> </table></div><h2>Grades</h2> <div class="box"> <table class="tFormat"> <th>Head</th> <tr>1</tr> </table></div>\[/code\]I was wondering how would I get the table under "Results"I've tried:\[code\] var nodes = doc.DocumentNode.SelectNodes("//h2"); foreach (var o in nodes) { if (o.InnerText.Equals("Results")) { foreach (var c in o.SelectNodes("//table")) { Console.WriteLine(c.InnerText); } } }\[/code\]It works but it also gets the table under Grades h2
 
Back
Top