views:

53

answers:

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  A: 

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

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

Sky Sanders
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.
DMan
yeah, your right. its been a while since i used hap. It is the bomb. glad i could help.
Sky Sanders