I'm trying to extract information from within a DIV that contains all between 2-6 tables with HtmlAgilityPack.
As long as there are the same amount of tables I can get the information without any problems by using
var thirdTable = res.SelectSingleNode("table[3]");
Each table contains tds and the first one contains the name I want to check for. At the moment it's done by
<table border="0" cellspacing="1" cellpadding="4" width="100%">
<tbody>
<tr bgcolor="#505050">
<td colspan="2" class="white">
<b>Character Deaths</b>
</td>
</tr>
</tbody>
</table>
var charTest = thirdTable.ChildNodes[0].InnerText.StartsWith(checkInfo);
but since the amount of tables differs from time to time I cannot extract the information without having a NullReferenceException.
How can I check the amount of tables then tell which tables that exists?
EDIT:
var URLCharacter = "http://www..." + tbSearch.Text;
HtmlAgilityPack.HtmlWeb doc = new HtmlAgilityPack.HtmlWeb();
htmldocObject = doc.Load(URLCharacter);
//Find the right contentdiv
var res = htmldocObject.DocumentNode.SelectSingleNode("//div[@class='BoxContent']");
res
?