using System;
class Google
{
const string key = "claveofrecidaporgoogle";
int start;
int maxResults;
bool filter;
bool safeSearch;
static void Main(string[] args)
{
try
{
Google google = new Google();
google.Search(args[0]);
}
catch (System.IndexOutOfRangeException e)
{
Console.WriteLine("Uso: Google QUERY");
}
catch(Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
Google()
{
this.start = 0;
this.maxResults = 10;
this.filter = true;
this.safeSearch = false;
}
void Search(string query)
{
Console.WriteLine("Buscando \"{0}\" en Google...", query);
GoogleSearchService search = new GoogleSearchService();
GoogleSearchResult result = search.doGoogleSearch(key, query, start, maxResults, filter, "", safeSearch, "", "", "");
Console.WriteLine("{0} resultados encontrados en {1} segundos.", result.estimatedTotalResultsCount, result.searchTime);
if(result.resultElements.Length > 0)
{
Console.WriteLine("Mostrando los {0} primeros:", result.resultElements.Length);
for(int i = 0; i < result.resultElements.Length; i++)
{
Console.WriteLine();
Console.WriteLine("{0}.{1}", i+1, result.resultElements[i].URL);
Console.WriteLine("\t{0}", result.resultElements[i].title);
}
}
}
}