At the Forge - Google Web Services
Listing 1. google-query.pl
#!/usr/bin/perl
use strict;
use diagnostics;
use warnings;
use SOAP::Lite;
# ------------------------------------------------------------
# Get the Google key from ~/.google_key
my $google_key_file = "/Users/reuven/.google_key";
open GOOGLE_KEY, $google_key_file or die "Cannot read
'$google_key_file': $! ";
my ($google_key) = <GOOGLE_KEY>;
chomp $google_key;
close GOOGLE_KEY;
# ------------------------------------------------------------
# Get the command-line argument
if ($#ARGV != 0)
{
print "$0: Invoke with a single argument, your Google search term.\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 the WSDL to make the 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}};
if (@results)
{
# Iterate through each result we got
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 value? If so, display it accordingly
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 a simple string
else
{
print "\t'$key' => '$value'\n";
}
}
$counter++;
}
}
else
{
print "There were no results for your query of '$query_string'.\n";
}
Most people, including myself, typically want to query the widest possible number of Web pages with our queries; however, there are times when it is more appropriate to retrieve data only from servers in a particular geography or in a certain language. The fact that Google's API makes this possible and straightforward opens the door for many different interesting applications.
Just as we send a query to Google via SOAP-encoded XML, we receive a result in SOAP-encoded XML. But as SOAP::Lite shielded us from having to write even a tiny bit of XML for the query, we similarly will be insulated when it comes to the response. The $results variable provides a Perl interface to the data that we received in response.
And exactly what data will we receive? To know that, we can look at the WSDL file once again. It indicates (among other things) that we will receive responses as a set of results, each of which looks like this:
<xsd:complexType name="ResultElement">
<xsd:all>
<xsd:element name="summary" type="xsd:string"/>
<xsd:element name="URL" type="xsd:string"/>
<xsd:element name="snippet" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="cachedSize" type="xsd:string"/>
<xsd:element name="relatedInformationPresent" type="xsd:boolean"/>
<xsd:element name="hostName" type="xsd:string"/>
<xsd:element name="directoryCategory" type="typens:DirectoryCategory"/>
<xsd:element name="directoryTitle" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
In other words, each search result we receive back from Google (up to a maximum of ten) will provide all of the information we need to create a results page that looks just like Google's. Moreover, we can pick and choose the elements we want to display, showing (for example) only the title and the dmoz directory category and title. Or we can show a short snippet from the searched page. Or all of these. Or none of these.
doGoogleSearch is not the only method described in the WSDL file. There also are other methods, such as working with Google's cached pages and checking the spelling of individual words. When Web services were first unveiled to the public, a common example was that a word processor would now be able to call a remote Web service for spell-checking, rather than coming with a built-in system. That day is still far off in the future, but you can imagine using Google's API for an experimental version of such a service.
Moreover, we can use these outputs as inputs into another Web service call, either locally or remotely. Combining data from multiple sites is an increasingly popular thing to do, especially when combined with Google's maps API. It's amazing to see what can happen when you combine services in this way—something that we will explore in the coming months.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Non-Linux FOSS: libnotify, OS X Style
- Linux Systems Administrator
- Validate an E-Mail Address with PHP, the Right Way
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Introduction to MapReduce with Hadoop on Linux
- RSS Feeds
- Bought photoshop CS5 for developing a website :(
2 hours 51 min ago - What the author describes
4 hours 18 min ago - Reply to comment | Linux Journal
8 hours 28 min ago - Reply to comment | Linux Journal
9 hours 13 min ago - Didn't read
9 hours 24 min ago - Reply to comment | Linux Journal
9 hours 29 min ago - Poul-Henning Kamp: welcome to
11 hours 39 min ago - This has already been done
11 hours 40 min ago - Reply to comment | Linux Journal
12 hours 25 min ago - Welcome to 1998
13 hours 13 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Google won't give me the key and code for web page : Google maps
Google maps are terribly inaccurate.
Google DO NOT provide :
Advanced Geocoding
Option for Large Static Maps
service Level Agreement
Technical Support
Support portal & usage reporting
Google maps for business is a basic mapping service for API and is not always free. The customisation is poor, and the coverage is not great, seldom recognising small towns and only to postcode accuracy as NO geocoding !
If something is good enough, they would not give it away !
i prefer a Viamichelin solution, much more professional
Just had this back from a business who has moved to Google to ViaMichelin !
Initially Simplytrax used a product I trialed and it stank (2008) and I told them I can only assume that this is a joke.
They have sinced changed provider and told me that Google maps are terrible unlike our new system with benefits from enhanced ViaMichelin technology.
Google maps web service is about the worst mapping I have seen and I have seen most mapping systems. No reputable company would use Google API.
Our new platform uses a viamichelin business web service which far surpasses anything we have seen before.
More coverage, better accuracy and support and a world recognised brand for quality for a price less than I thought ( ViaMichelin were Cheaper than the Google enterprise Ajax API we solution by 25% with straight forward Javascript coding !
Mark Boardman of ViaMichelin business UK stated " We are pleased to have secured this contract to ensure the continued success of SimplyTrax"
Nick
Simply Trax
Google won't give me the key and code for web page
Dear Reuven,
Congratulations for your article!
I've registered a Google account this morning but still haven't received an email with the file... Is it normal this way?
I'd like to use your perl script embedded into a web page but I work with PHP. Is there a simple way to put that perl code to work on a web page assuming the parameters came from a form?
I assume PHP 4 manages SOAP, can I work with PHP/SOAP?
Thanks
Gabriel Menini
Linux Registered User #207262