I need to get info from two tables:
I iterate every table and from every table I get the info from the td
But I get the info two times and the orderingText is filled x2, so to prevent the second iteration I put a break to stop it but I think is not the way how it works HtmlAgilityPack or I’m doing something wrong
// Get the node from the div
//
HtmlNode orderingProcNode = docProcSpecs.DocumentNode.SelectSingleNode("//div[@id='orderingordering']");
string[] orderingText = new string[1024];
int t = 0;
// Iterate each table
foreach (HtmlNode orderingProcessor in orderingProcNode.SelectNodes("//table[@class='noSort infoTable']"))
{
foreach (HtmlNode ordProcessor in orderingProcessor.SelectNodes("//tbody//tr//td"))
{
// Here I get all the info from the two tables instead of one table
//
orderingText[t++] = ordProcessor.InnerText.Trim();
}
break; // this is the solution
}
The problem is the inner
foreachloop – you are selecting alltbodynodes in the document, where you really want all child nodes of the current node – just remove the forward slashes: