I have the current HTML layout
<table> //table[1]
</table>
<table> //table[2]
<tbody>
<tr>
<td>
<p>
</p>
</td>
</tr>
<tr>
<td>
<table> //table[1]//table[1]
<tbody>
<tr>
<td>
<p>
INFO 1
</p>
</td>
<td>
<p>
INFO 2
</p>
</td>
<td>
<p>
INFO 3
</p>
</td>
<td>
<p>
INFO 4
</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table> //table[1]//table[2]
<tbody>
<tr>
<td>
<p><strong>Name</strong></p>
</td>
<td>
<p><strong>Quantity</strong></p>
</td>
</tr>
<tr>
<td>
<p>Apples </p>
</td>
<td>10</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table> //table[1]//table[3]
</table>
</td>
</tr>
</tbody>
</table>
I am trying to get the data within //table[1]//table[2]
, yet I keep getting a null HtmlNode (System.NullReferenceException
) for the following:
doesn't' work: doc.DocumentNode.SelectSingleNode("//table[2]//tbody//tr//td//table[2]//tbody//tr");
,
I am not sure why this occurs as when I try to get data for //table[1]//table[1]
it works just fine with this syntax
works: doc.DocumentNode.SelectSingleNode("//table[2]//tbody//tr//td//table[1]//tbody//tr");
Am I misunderstanding how the indexing works with Html Agility Pack?