17 August 2009

GoogleSearch with SOAP - perl

------------------google.pl------------------
#!/usr/bin/perl

use SOAP::Lite;
use strict;
use warnings;

@ARGV == 2 or die "Usage: google <query> <number of results 1-10>\n";

my $key='OS7mOjxQFHIztxIYU9yb8y3ibYgY4w2o';

my($query, $maxResults) = @ARGV;

my @params = ($key, $query, 0, $maxResults, 0, '', 0, '', 'latin1', 'latin1');

my $result = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl")->doGoogleSearch(@params);

print "Result: \n";

print join "\n", map( { qq{$_->{URL}} } @{$result->{resultElements}} ), "";
---------------------------------------------

1. Download SOAP for Perl from here.
2. tar xzvf SOAP-Lite-0.60a.tar.gz
3. cd SOAP-Lite-0.60/lib
4. chmod 755 google.pl
5. ./google.pl ls 10

Reference:
perl-google-soap-example
http://search.cpan.org/~byrne/SOAP-Lite/lib/SOAP/Lite

No comments:

Post a Comment