The Code
Here's a classic piece of Perl code to produce a
Google box as a regular text file filled with garden-variety HTML
code, suitable for incorporating into any web page.
#!/usr/local/bin/perl
# google_box.pl
# A classic Google box implementation.
# Usage: perl google_box.pl <query> <# results>
# Your Google API developer's key.
my $google_key='insert key here';
# Location of the GoogleSearch WSDL file.
my $google_wdsl = "./GoogleSearch.wsdl";
use strict;
use SOAP::Lite;
# Bring in those command-line arguments.
@ARGV == 2
or die "Usage: perl googlebox.pl <query> <# results>\n";
my($query, $maxResults) = @ARGV;
$maxResults = 10 if ($maxResults < 1 or $maxResults > 10);
# Create a new SOAP::Lite instance, feeding it GoogleSearch.wsdl.
my $google_search = SOAP::Lite->service("file:$google_wdsl");
# Query Google.
my $results = $google_search ->
doGoogleSearch(
$google_key, $query, 0, $maxResults, "false", "",
"false", "", "latin1", "latin1"
);
# No results?
@{$results->{resultElements}} or die "no results";
print join "\n",
map( {
qq{<a href="$_->{URL}">} .
($_->Capture Google Results in a Google Box || $_->{URL}) .
qq{</a> <br />}
} @{$results->{resultElements}} );
Save the code to a file called google_box.pl. Be
sure to replace insert keyhere in the seventh line with your
personal Google API key.