Skip to content

Get results count from google with HttpWebRequest

Csharp Ninja

Asked Apr 21, 2012, 7:30 AM EDT2 answers
Share
LinkedInX
I can't get results count from google with webrequest class....

here is a google search:

https://www.google.com/#hl=en&safe=off&sclient=psy-ab&q=csharp&oq=csharp&aq=f&aqi=g-s1g3&aql=&gs_nf=1&gs_l=hp.3..0i10j0l3.630367.631926.1.632221.6.6.0.0.0.0.377.1510.2-5j1.6.0.bQ6f0KVqlJo&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=658b538c23bb4e18

and result count of the search:
11,300,000

I wrote:

                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.google.com/#hl=en&safe=off&output=search&sclient=psy-ab&q=yo&oq=yo&aq=f&aqi=g4&aql=&gs_nf=1&gs_l=hp.3..0l4.966.1226.0.1551.2.2.0.0.0.0.157.313.0j2.2.0.FSg1sDuz3RY&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=658b538c23bb4e18");
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                StreamReader s = new StreamReader(resp.GetResponseStream(), Encoding.ASCII);
                string result = s.ReadToEnd();
                int one = result.IndexOf("");
                int two = result.Substring(one).IndexOf("
");
                textBox1.Text = result.Substring(one, two);

but it doesn't work...

BUT I can get title text from google with this code:


                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.google.com/#hl=en&safe=off&output=search&sclient=psy-ab&q=yo&oq=yo&aq=f&aqi=g4&aql=&gs_nf=1&gs_l=hp.3..0l4.966.1226.0.1551.2.2.0.0.0.0.157.313.0j2.2.0.FSg1sDuz3RY&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=658b538c23bb4e18");
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                StreamReader s = new StreamReader(resp.GetResponseStream(), Encoding.ASCII);
                string result = s.ReadToEnd();
                int one = result.IndexOf("");
                textBox1.Text = result.Substring(one, two);

why I can't get results count.... help me please

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    188 views but still no reply.... ?????
    0
  • 1 short reply