Quantcast
Channel: htmlagilitypack Forum Rss Feed
Viewing all articles
Browse latest Browse all 655

New Post: "//div[@id='resultStats']" Error

$
0
0

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.


Viewing all articles
Browse latest Browse all 655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>