Hacking oreilly google hacks, 1st edition

Page 125

$_->{URL} = $_->{URL}->{content}; ref $_->{snippet} eq 'HASH' and $_->{snippet} = ''; ref $_->{title} eq 'HASH' and $_->{title} = ''; } return $results->{GoogleSearchResult}; } 1;

36.4 Using the XooMLe Module Here's a little script to show our home-brewed XooMLe module in action. Its no different, really, from any number of hacks in this book. The only minor alterations necessary to make use of XooMLe instead of SOAP::Lite are highlighted in bold.

#!/usr/bin/perl # xoomle_google2csv.pl # Google Web Search Results via XooMLe 3rd party web service # exported to CSV suitable for import into Excel # Usage: xoomle_google2csv.pl "{query}" [> results.csv] # Your Google API developer's key my $google_key = 'insert key here'; use strict; # Uses our home-brewed XooMLe Perl module # use SOAP::Lite use XooMLe; $ARGV[0] or die qq{usage: perl xoomle_search2csv.pl "{query}"\n}; # Create a new XooMLe object rather than using SOAP::Lite # my $google_search = SOAP::Lite>service("file:$google_wdsl"); my $google_search = new XooMLe; my $results = $google_search -> doGoogleSearch( $google_key, shift @ARGV, 0, 10, "false", "", "false", "", "latin1", "latin1" ); @{$results->{'resultElements'}} or warn 'No results'; print qq{"title","url","snippet"\n}; foreach (@{$results->{'resultElements'}}) { $_->{title} =~ s!"!""!g; # double escape " marks $_->{snippet} =~ s!"!""!g; my $output = qq{"$_->{title}","$_->{URL}","$_>{snippet}"\n};


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.