簡體   English   中英

C#HtmlAgilityPack用於節點數組

[英]c# HtmlAgilityPack for on nodes array

我正在使用html敏捷包,並在得到節點數組之后:

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

現在我想為每個節點運行一個for循環[i]。 我已經試過了:

 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數組不關注node [i]。 但會在html文件中顯示所有(“ // td [@ class ='artist']”)的數組。 救命?

使用//td[@class='artist']將從您的document.DocumentNode獲取具有artist類的所有列。

使用.//td[@class='artist'] (請注意開頭的點)將從當前選定的節點(在您的情況下為nodes[i] )中獲取所有具有artist類的列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM