Google Optimization
  Home arrow Google Optimization arrow Page 2 - Using the Google SOAP Search API
SEO Chat Forums  
Choosing Keywords  
Google Optimization  
Link Trading  
MSN Optimization  
Search Engine News  
Search Engine Spiders  
Search Optimization  
Web Directories  
Website Marketing  
Website Promotion  
Website Submission  
Yahoo Optimization  
SEO Tools
Adsense Calculator
AdSense Preview
Advanced Meta-Tags
Alexa Rank Tool
Check Server Headers
Class C Checker
Code to Text Ratio
CPM Calculator
Domain Age Check
Domain Typos
Future PageRank
Google Dance
Google Keywords
Google Search
Google Suggest
Google vs Yahoo
Indexed Pages
Keyword Cloud
Keyword Density
Keyword Difficulty
Keyword Optimizer
Keyword Position
Keyword Typos
Link Popularity
Link Price Calculator
Meta Analyzer
Meta Tag Generator
Multiple Link Popularity
Page Comparison
Page Size
PageRank Lookup
PageRank Search
Robots.txt Generator
ROI Calculator 
S.E. Comparison 
S.E. Keyword Position 
Site Link Analyzer 
Spider Simulator 
URL Redirect Check 
URL Rewriting 
Mobile Linux 
APP Generation ROI 
IBM® developerWorks 
SEO Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
GOOGLE OPTIMIZATION

Using the Google SOAP Search API
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 20
    2006-09-27

    Table of Contents:
  • Using the Google SOAP Search API
  • Performing a Google Search
  • Cached Pages
  • Asynchronous Calls

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using the Google SOAP Search API - Performing a Google Search


    (Page 2 of 4 )

    Google searches can be conducted through the doGoogleSearch method, which returns a GoogleSearchResult object. The method, however, takes a number of arguments: a string containing your license key, a string containing the query, an integer representing the first result you wish to retrieve (starting at zero), an integer representing the maximum number of results you wish to retrieve (the maximum is ten), a boolean turning search filtering on or off (this eliminates similar results), a string restricting results to a certain country or topic, a boolean turning SafeSearch on or off, a string restricting results to a certain language, and two more strings to specify encoding—arguments which are now disregarded.

    Here, we query Google with “Developer Shed” and store the results in search:

            GoogleSearchResultsearch = google.doGoogleSearch("x0x0",
    "Developer Shed", 0, 10, true, "", true, "", "", "");

    You will, of course, have to substitute the first argument with your own license key.

    The above line of code tells the SOAP Search API to return ten results starting from the very first result obtained. Search filtering is turned on, which, as stated earlier, trims down the results by eliminating near-duplicate results. SafeSearch is turned on, and the results are not restricted to any language, topic or country.

    We can obtain the results of the query through search, starting with some general information:

            Console.WriteLine("Query "{0}" completed in {1}
    seconds."
    , search.searchQuery,
                search.searchTime);
            Console.WriteLine("Estimated number of results: " +
    search.estimatedTotalResultsCount);

    Above, we display the query text, the amount of time the query took and the estimated number of results.

    We can also access the results themselves (well, ten of them). Here, we iterate through the results and print a summary:

            foreach (ResultElement result in search.resultElements)
            {
                Console.WriteLine("n" + result.title);
                Console.WriteLine(result.URL);
                Console.WriteLine(result.snippet);
            }

    As you can see, resultElements contains an array of ResultElement objects. A foreach loop is used to iterate through this array. Unfortunately, a bit of HTML is also included, and we may not always want that. However, regular expressions can fix this problem easily enough:

            Regex stripHtml = new Regex("<(.+?)>");
            foreach (ResultElement result in search.resultElements)
            {
                Console.WriteLine("n" + stripHtml.Replace
    (result.title, ""));
                Console.WriteLine(result.URL);
                Console.WriteLine(stripHtml.Replace(result.snippet,
    ""));
            }

    Now let's say we need the next five results. To retrieve them, simply increase the starting index by ten and set the maximum number of results to five:

            search = google.doGoogleSearch("x0x0", "Developer Shed",
    10, 5, true, "", true, "", "", "");

    The results can be modified significantly by turning filtering off:

            GoogleSearchResultnoFilter = google.doGoogleSearch
    ("x0x0", "Developer Shed", 0, 10, false, "", true, "", "", "");

    This produces a number of similar results. In most cases, this is undesired behavior, since a smaller variety of information is returned in a single query. However, the feature can be turned off, as we did above, in case you find some reason to do so.

    Making use of country, topic and language restrictions is easy. For example, the following query returns results restricted to the German language and the German country. The country of a result is based on its top level domain and IP address.

            GoogleSearchResult germanSearch = google.doGoogleSearch
    ("x0x0", "Geschichte", 0, 10, true, "countryDE", true, "lang_de",
    "", "");

    Google also provides a few topics that searches can be restricted to: American government (“unclesam”), Linux (“linux”), Macintosh (“mac”) and FreeBSD (“bsd”). Here, we restrict results to American government:

            GoogleSearchResult govSearch = google.doGoogleSearch
    ("x0x0", "John Paul Jones", 0, 10, true, "unclesam", true, "",
    "", "");

    Google provides a full list of country, topic and language restrictions on the SOAP Search API website:

    http://www.google.com/apis/reference.html#2_4

    More Google Optimization Articles
    More By Peyton McCullough


       · The article was very informative. I liked it very much as i have got some...
       · Thank you for your comment!The Google SOAP Search API is pretty interesting, but...
       · Google seems to implictly (but not explicitly) accept everyone using their Google...
     

    GOOGLE OPTIMIZATION ARTICLES

    - Google Adwords Guide
    - Create a Customized Google XML Sitemap
    - Google Website Optimizer Review
    - Using Analytics to Understand Your Readers
    - Google Sandbox Effect
    - Improve Google Indexing on Your Ecommerce We...
    - Back Links and Google Page Rank
    - The Five Most Important Things You Can Do wi...
    - Advanced Traffic Analysis Techniques with Go...
    - How to Build an Online Survey with Google Do...
    - How to Analyze and Rate Keyword Difficulty i...
    - Using Analytics on Your Site
    - Google Algorithms
    - How Google`s Quality Raters Treat Web Spam
    - Google`s Quality Rater Guidelines Leaked





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek