简体   繁体   中英

c# HtmlAgilityPack for on nodes array

I'm using html agility pack and after I got array of nodes:

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

now i want to run a for loop one each nodes[i]. I've tried this:

 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      }

the problem is that the itemtext array isn't focusing on nodes[i] . but brings out an array of all the ("//td[@class='artist']") in the html document. help?

Using //td[@class='artist'] will fetch all columns with artist class from your document.DocumentNode .

Using .//td[@class='artist'] (Notice the dot at the begining) will fetch all columns with artist class from the current selected node, which in your case is nodes[i] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM