Capture results using HtmlAgilityPack

1

I am using this code to search results using the Html Agility Pack. It looks like this:

WebRequest request = WebRequest.Create(texto);
        WebResponse response = request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
        string Texto = reader.ReadToEnd();

        var doc = new HtmlAgilityPack.HtmlDocument();
        doc.LoadHtml(Texto);
        var links = doc.DocumentNode.SelectNodes("//a[contains(text(),'2')][@href]");

        if (links != null)
        {
            foreach (HtmlNode link in links)
            {
                var href = link.Attributes["href"].Value;
                MessageBox.Show(href);
            }
        }

The code idea is: Look for a tag like this:

<a href="/t439-teste">2</a>

The code I have worked correctly and get the results. The problem is that it is capturing the results that have 2 as a whole, I want it to only capture only those that have EXACTLY the 2, it alone. How?

Thanks in advance for the help.

    
asked by anonymous 19.07.2016 / 22:17

1 answer

2

So will not it work?

var links = doc.DocumentNode.SelectNodes("//a").where(x => x.innerHTML == "2");
    
05.10.2016 / 19:49