8

Whenever you perform a Google search, it spits out this little snippet of info

"About 8,110,000 results (0.10 seconds)"

I'm using the number of results certain terms return to rank them against each other, so if I could get this integer - 8,110,000 - via the API it would be very helpful. Some Google API's have recently been deprecated, so if you could point me to the right one that isn't deprecated, it would be very helpful.

Any other workarounds would also be much appreciated. I've seen one or two old posts on similar topics, but none seemed to be resolved successfully.

varunsrin
  • 860
  • 2
  • 15
  • 24
  • 2
    Would be nice to see a Google solution too :) – UpTheCreek Mar 25 '11 at 13:38
  • I couldn't find a Google API or page that exposed the total number of results - of course you could scrape the webpage instead of the API, but that is generally frowned upon and my app was for a phone, so that would have just been resource intensive. – varunsrin Apr 16 '11 at 07:23

1 Answers1

5

Completed using Bing instead of Google and with the following code:

string baseURL = "http://api.search.live.net/xml.aspx?Appid=<MyAppID>&query=%22" + name + "%22&sources=web";
WebClient c = new WebClient();
c.DownloadStringAsync(new Uri(baseURL));
c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(findTotalResults);

and this calls findTotalResults:

void findTotalResults(object sender, DownloadStringCompletedEventArgs e)
{
    lock (this)
    {
        string s = e.Result;
        XmlReader reader = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(s)));
        while (reader.Read())
        {
            if (reader.NodeType == XmlNodeType.Element)
            {
                if (reader.Name.Equals("web:Total"))
                {
                    gResults = reader.ReadInnerXml();
                }

            }
        }
    }
}
Hooked
  • 84,485
  • 43
  • 192
  • 261
varunsrin
  • 860
  • 2
  • 15
  • 24