1

I've seen some results on StackOverflow already on a similar topic and they all recommended the HTML Agility Pack. I've also found a few examples on it too, but it isn't working. My current code:

        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
        doc.LoadHtml("http://stackoverflow.com/");
        List<string> facts = new List<string>();
        foreach (HtmlNode li in doc.DocumentNode.SelectNodes("//div"))
        {
            facts.Add(li.InnerText);
            foreach (String s in facts)
            {
                textBox1.Text += s + "/n";
            }
        }

I get the error Null reference was unhandled on doc.DocumentNode.SelectNodes("//div").

Also, as another question, how do I find a specific div with a name?

1 Answer 1

1

as to q1: it looks right to me. Are you certain the document is loaded properly..

r.e. q2: use xpath: div[@id='idToFind']

Sign up to request clarification or add additional context in comments.

2 Comments

Oh, I think I got it. LoadHTML doesn't support URI's it seems, so I have to load an actual webpage from my computer I believe.
yeah, your right. its been a while since i used hap. It is the bomb. glad i could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.