I've seen some r开发者_StackOverflow社区esults 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?
as to q1: it looks right to me. Are you certain the document is loaded properly..
r.e. q2: use xpath: div[@id='idToFind']
精彩评论