Google SVG Search I (1/2) - exploring XML | WebReference

Google SVG Search I (1/2) - exploring XML

Google SVG Search I

In the next couple of installments we will make use of our previously acquired knowledge on the Google Web Services API and SVG in order to produce a CGI that graphically presents the search engine results returned by Google.

Installing SOAP::Lite

We will start at the Web services end of things and use perl's SOAP::Lite package to build a SOAP client that will use Google's API to retrieve search engine results for any given query. First we need to install SOAP::Lite from the Comprehensive Perl Archive Network, which is pretty much CPAN standard:

perl -MCPAN -e 'install SOAP::Lite'

Or if you do not have CPAN.pm installed, download the package from the above location, untar and run:

   perl Makefile.PL
   make
   make test
   make install

SOAP::Lite comes, despite its name, with full-blown inplementations for stand-alone SOAP clients, CGI clients and servers, and stand-alone SOAP servers with HTTP support. It is also the most advanced free Perl toolkit on the block by being able to dynamically generate all necessary code automatically from a Web Services Definition Language (WSDL) file. Other toolkits and languages require you to manually generate code or even hand-code it yourself.

Calling Google via SOAP

All this makes our first step of the project, retrieving query results from Google, really easy:

#!/usr/bin/perl -w
use strict;
use SOAP::Lite;
my $googleSearch = SOAP::Lite->service('file:GoogleSearch.wsdl');
my $key = '00000000000000000000000000000000';
my $query = 'exploring XML';
$ENV{HTTP_proxy} = 'http://proxy:3128';
my $result = $googleSearch->doGoogleSearch($key, $query, 0, 10, 'false', '', 'false', '', 'latin1', 'latin1');

We simply need to include the SOAP::Lite package and point it at the WSDL file included in the download from Google. From then on we can call all the functions defined in the service description, passing the right parameters. Google decided to make this service available for free in the beta phase, but requires everybody to register at their site and obtain a key that allows them to track your requests. This key needs to be passed along with the main function parameter, the actual query string.

Since the default transport for SOAP is HTTP, we might have to set the HTTP proxy in the environment if one is in the way. Then we are prepared to call the doGoogleSearch function which is automagically created for us by the service call on the WSDL file. The subsequent arguments to the function call deal with less important parameters.

More search parameters...


Produced by Michael Claßen

URL: http://www.webreference.com/xml/column55/index.html
Created: Apr 29, 2002
Revised: Apr 29, 2002