#!/usr/bin/perl use strict; use warnings; use SOAP::Lite; #-------------------------- #Get the google key my $google_key="ozFwF9NQFHKVyPJJlhIx39BmAe76UXvY"; #-------------------------- #Get the command line arg if ($#ARGV !=0) { print "$0: Invoke with single argument.\n"; exit; } my $query_string = shift @ARGV; #-------------------------- #GET the WSDL file my $google_wsdl = "http://api.google.com/GoogleSearch.wsdl"; my $query = SOAP::Lite->service($google_wsdl); #-------------------------- #Use WSDL file to make query my $starting_page = 1; my $max_results = 10; my $filter = 'false'; my $geographic_restriction = ''; my $safe_search = 'false'; my $language_restriction =''; my $results = $query->doGoogleSearch($google_key, $query_string, $starting_page, $max_results, $filter, $geographic_restriction, $safe_search, $language_restriction, 'utf-8', 'utf-8'); my @results = @{$results->{resultElements}}; print "Content-Type: text/html; charset=iso-8859-1"; print ""; if (@results) { #iterate through results my $counter =1; foreach my $result (@results) { print "Result $counter of ", $#results +1, ":\n"; foreach my $key (sort keys %{$result}) { my $value = $result->{$key}; #Is this a hash? if so display if (UNIVERSAL::isa($value, 'HASH')) { print "\t'$key':\n"; foreach my $subkey (sort keys %{$value}) { print "\t\t'$subkey' => '$value->{$subkey}'\n"; } } #Display the value as string else { print "\t'$key' => '$value'\n";} } $counter++; } } else {print "There were no results for your query of '$query_string'.\n";}