Google to RSS with SOAP

Google, the search engine of fashion these days, is as close to an authority as you can get on the Internet. If it’s not mentioned on Google, the feeling is, it’s not really online. And if it is, conversely, then people will find it. Keeping track of things in Google’s database, therefore, is an important job. Whether you are trying to find things out or monitoring for other people’s discoveries, an RSS feed is the perfect way to do it. Happily, Google provides a nice interface to work with its systems. This makes things very easy.

Walking Through the Code

We start, as ever, with the usual pragmas, CGI and XML::RSS. This time, you also need SOAP::Lite and HTML::Entitie.

use warnings;
use strict;
use XML::RSS;
use CGI qw(:standard);
use HTML::Entities ( );
use SOAP::Lite;

We’ll set up the query term, and the Google API key, from the CGI input. Then, we fire up the SOAP::Lite by pointing it at Google’s WSDL file. WSDL files contain the finer details of a SOAP interface, telling the script exactly where to send commands and so on.

my $query = param("q");
my $key   = param("k");

my $service = SOAP::Lite -> service('http://api.google.com/GoogleSearch.wsdl');

Now, run the search using the SOAP interface we just set up; then set up the feed:

my $result = $service -> doGoogleSearch ($key, $query, 0, 10, "false", "", "false","", "latin1", "latin1"); my $rss = new XML::RSS (version => '2.00'); $rss->channel( title => "Google Search for $query", link => "http://www.google.com/search?q=$query", ...

Get Developing Feeds with RSS and Atom now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.