2017-02-28 89 views
0

我使用的HTML敏捷包和我的节点后阵:C#HtmlAgilityPack对节点阵列

HtmlNode[] nodes = document.DocumentNode.SelectNodes("//tbody[@class='table']").ToArray(); 

现在我想运行一个for循环每一个节点[1]。我试过这个:

for (int i = 0; i < 1; i++) 
      { 

       if (t == null) 
        t = new Model.Track(); 

       HtmlNode[] itemText = nodes[i].SelectNodes("//td[@class='artist']").ToArray(); 

       for (int x = 0; x < itemText.Length; x++) 
       { //doing something  } 

问题是itemtext数组没有关注节点[i]。 ,但在html文档中显示了所有(“// td [@ class ='artist']”)的数组。 有帮助吗?

+0

你能分享你要通过这个或HTML获取的链接吗? –

+0

我已经得到了正确的答案zroq,无论如何。 – hhh

回答

0

使用//td[@class='artist']将从您的document.DocumentNode中获取artist类的所有列。

使用.//td[@class='artist'](注意开头的小圆点)将从当前所选节点中获取artist类的所有列,您的情况为nodes[i]

+0

这么简单,但花了很多时间,谢谢你。 – hhh