HTML Agility Pack - Get Text From 1st STRONG Tag Inside SPAN Tag

c# html-agility-pack html-parsing

Question

There are 5 STRONG Tags inside my SPAN Tag from my Html document. I want to know how to get the text from the first STRONG Tag inside the SPAN TAG?

Here is my code so far.

        var web = new HtmlWeb();
        var doc = web.Load(url);

        var nodes = doc.DocumentNode.SelectNodes("//span[@class='advisory_link']/strong");

        foreach (var node in nodes)
        {
            richTextBox1.Text = node.InnerHtml;
        }

Accepted Answer

        var nodes = doc.DocumentNode.SelectNodes("//span[@class='advisory_link']//strong[1]");

        if (nodes != null)
        {
            foreach (var node in nodes)
            {
                string Description = node.InnerHtml;
                return Description;
            }
        }

        return null;



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why