0

I am trying to identify the second table using HTMLAgilityPack

<center>
<table>
<tr>
<td>0-A</td> <td>&nbsp|&nbsp;</td>
<td>B</td> <td>&nbsp|&nbsp;</td>
<td>C</td> <td>&nbsp|&nbsp;</td>
</tr>
</table>
</center>
<br><br>
<TABLE DIR=LTR BORDER>
<TR>
<TD DIR=LTR ALIGN=RIGHT><b>A</b></TD>
<TD DIR=LTR ALIGN=LEFT><b>B</b></TD>
<TD DIR=LTR ALIGN=LEFT><b>C</b></TD>
</TR>
</TABLE>

I have tried

Dim table = doc.DocumentNode.SelectSingleNode("//table[2]")

and that does not work. I have tried it as a capital and that does not work. If I put "//table[1]" I do find the first table. Is there a different way that I should do this? I'm doing this in VB.net

Additional information when I do

 For Each x_table As HtmlNode In doc.DocumentNode.SelectNodes("//table")

it finds two tables and I can skip the first and work on the second, but is that the way it was designed to work?

Bill
  • 1,423
  • 2
  • 27
  • 51
  • Does `(//table)[2]` work? (From [XPath query to get nth instance of an element](https://stackoverflow.com/a/4008925/1115360).) – Andrew Morton Feb 23 '19 at 22:04
  • You can use SelectNodes and then use the indexer: Dim table2 = doc.DocumentNode.SelectNodes("//table")(2); – bdn02 Feb 23 '19 at 23:10
  • doc.DocumentNode.SelectNodes("//table")(1) worked for the second table-- and (0) for the first. Thanks (//table)[2] would not compile in VB – Bill Feb 24 '19 at 13:27

0 Answers0