#!/usr/local/bin/perl
# goolucky.cgi
# Gleans the domain from the first (read: top) result returned, allows
# you to overlay another query, and returns the results, and so on...
# goolucky.cgi is called as a CGI with form input.
# 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;
use CGI qw/:standard/;
# Create a new SOAP instance.
my $google_search = SOAP::Lite->service("file:$google_wdsl");
# If this is the second time around, glean the domain.
my $query_domain = param('domain') ? "inurl:" . param('domain') : '';
my $results = $google_search ->
doGoogleSearch(
$google_key, param('query') . " $query_domain", 0, 10,
"false", "", "false", "", "latin1", "latin1"
);
# Set domain to the results of the previous query.
param('domain', $results->{'resultElements'}->[0]->{'URL'});
param('domain', param('domain') =~ m#://(.*?)/#);
print
header( ),
start_html("I'm Feeling VERY Lucky"),
h1("I'm Feeling VERY Lucky"),
start_form( ),
'Query: ', textfield(-name=>'query',
-default=>'"Grace Hopper"'),
' ',
'Domain: ', textfield(-name=>'domain'),
' ',
submit(-name=>'submit', -value=>'Search'),
p( ),
'Results:';
foreach (@{$results->{'resultElements'}}) {
print p(
b($_->Feel Really Lucky), br( ),
a({href=>$_->{URL}}, $_->{URL}), br( ),
i($_->{snippet})
);
}
print
end_form( ),
end_html( );