How do I Google a search with C#?

Asked

Viewed 1,548 times

1

I need to search for any term in Google and get a list of the results of this search. I’m trying to do this using the Google Custom Search API but I’m not getting satisfactory results.

For example, when I seek the term "bidding" with my code I get 1,510,000 results. When I search the same term directly in the browser I get 11,800,000 results.

How do I get all 11,800,000 of that research?

Below is my code in C#:

 static void Main(string[] args)
    {
        string apiKey = "AIzaSyCVGlnfsGaaJ3HYTHVu6OH_jBaIFJQYrH0";
        string cx = "013638634553566051485:xwnfxqp2pso";
        string query = "licitações";
        var svc = new Google.Apis.Customsearch.v1.CustomsearchService(
        new BaseClientService.Initializer { ApiKey = apiKey });
        var listRequest = svc.Cse.List(query);
        listRequest.Cx = cx;
        var search = listRequest.Execute(); //listRequest.Fetch(); This method has been removed
        foreach (var result in search.Items)
        {
            Console.WriteLine("Title: {0}", result.Title);
            Console.WriteLine("Link: {0}\n", result.Link);
        }
        Console.ReadKey();
    }

1 answer

1


Unfortunately, or fortunately, the numbers are different for some reasons.

Custom Search vs Google.com

In general, a custom search engine searches through a set of websites that you specify. However, you can set up your custom search engine to search the entire web. In this case, however, the results are unlikely to match those returned by Google Web Search, for several reasons:

  • Although a custom search engine is configured to search the entire Web, it is designed to highlight the results of your websites.
  • Your custom search engine does not include Google Web Search functions such as Onebox, real-time search results, universal search, social functions or custom results.
  • If your custom search engine includes more than ten sites, the results may come from a subset of our index and differ from the results of a "site:" search provider made on Google.com.

If you want to get more complete results in your custom search engine, try one of the following:

  • Section Search Preferences Basics tab Control Panel, select Search only the included websites. Be sure not to include more than ten sites in the sites tab. The domains you add to it will be included in the total count, but not the domain pages is taken into account.
  • Section Search Preferences guide Basics Control Panel, select Search on the web, but emphasize included locations .
  • Add restricted to your search engine that meets one of these missions requirements.

We have a similar question on our "older brother, if you want to verify.

Note: The text has been translated using Google Translate, so it may contain some translation errors. The original text can be found at this link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.