2012-02-27 49 views
1

我需要从两个表获取信息:迭代每个表,并获得信息

http://pastebin.com/BzbKPH2i

我遍历每个表,并从每个表我从TD的信息

但我得到的信息两次和orderingText填充x2,所以为了防止第二次迭代我把中断阻止它,但我觉得不是具体如何工作HtmlAgilityPack还是我做错事的方式

// 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 
} 

回答

0

的问题是内部foreach循环 - 你选择的文档,其中在所有tbody节点你真的希望所有子节点当前节点的 - 只是删除斜杠:

foreach (HtmlNode ordProcessor in orderingProcessor.SelectNodes("tbody/tr/td")) 
+0

pfff你的权利...谢谢! – tttony 2012-02-27 00:26:59