2012-02-27 75 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