Thursday, September 27, 2012

Playing With Google Search Results - 2

Another way of getting back web search results from Google is to use Google API. I've spent a couple of hours researching the option to do that, and did not find too many exciting choices. There is an option to use Google API which is deprecated, and limits the amount of searches to about 100 per day, and does not return more than 64 results, and does not allow automatic searches, or to use Google Custom Search, which can be used only to create site-specific custom searches. Anyway, as an exercise I decided to implement a call to Google API (deprecated one). There are a few options available.

The easiest way to use Google API I found was to use Google API for .NET. After I downloaded and referenced the GoogleSearchAPI.NET20 dll, it took me a surprisingly small amount of lines of code to create a quick prototype of querying the Google API

private void btnSearch_Click(object sender, EventArgs e)
{
 string searchTerms = txtTerms.Text;
 List<string> GoogleApiResults = GoogleAPI.StringResultList(searchTerms, 100);
}

public static class GoogleAPI
{
 public static GwebSearchClient client = new GwebSearchClient("");

 public static List<String> StringResultList(string terms, int number)
 {
  IList<IWebResult> list = client.Search(terms, number);
  List<String> results = new List<string>();
  foreach (var result in list)
  {
   results.Add(result.Url);
  }
  return results;
 }
}

Search Results

References

Google API for .NET by . Also posted on my website

No comments: