hi everbody. i want to get the google resultstas div. but i dont. i take error "Object reference not set to an instance of an object."
my code:
var doc = new HtmlWeb().Load("http://www.google.com/search?q=love");
var div = doc.DocumentNode.SelectSingleNode("//div[@id='resultStats']");
var text = div.InnerHtml.ToString(); <--- this line
textBox1.Text = div.ToString();
var matches = Regex.Matches(text, @"About ([0-9,]+) ");
var total = matches[0].Groups[1].Value;
i try this code:
int counter = 0;
HtmlWeb hw = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = hw.Load("http://www.google.com/search?q=love");
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
{
counter = counter + 1;
}
MessageBox.Show(counter.ToString());
i see 97 in the messagebox.
but i try this code:
HtmlWeb hw = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = hw.Load("http://www.google.com/search?q=love");
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
{
MessageBox.Show(link.ToString());
}
i see only "HtmlAgiliytPack.HtmlNode" in the messagebox 97 times.
whatever. please help me.
thanks.