0

In a webpage there are several nodes having class='inner'. But i need to the 3rd node having class='inner'. If i use

string x = textBox1.Text;
string q = "";

HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load("myweb_link" + x);
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@class='inner']");


if (nodes != null)
{

    foreach (HtmlNode n in nodes)
    {
        q = n.InnerText;
        q = System.Net.WebUtility.HtmlDecode(q);
        q = q.Trim();
        MessageBox.Show(q);
    }

}
else
    MessageBox.Show("nothing found ");

it gives me all the nodes having class='inner'. i also know that.

But i want only the 3rd node. How can i get that???

4

1 回答 1

0

Get the third node from the nodes variable using the indexer:

var thirdNode = nodes[2];
于 2013-03-30T20:02:56.567 回答