Google SVG Search I (2/2) - exploring XML | WebReference

Google SVG Search I (2/2) - exploring XML

Google SVG Search I

More search parameters

The following parameters handle scrolling through the result set, the character encoding of documents, and several search options:

start0The offset into the result set
maxResults10The number of elements to be returned
filterfalseshow similar results
restrict''Restriction by country or topic
safeSearchfalseshow all results
lr''Language restriction
ie'latin1'Input character encoding
oe'latin1'Output character encoding

Parsing the results

The result variable is created on the fly according to the response type for the doGoogleSearch call. In this case it is a top-level hashtable containing an array resultElements, which in turn holds a hashtable with information for each search result, such as summary, title, and URL. It also contains a further hashtable with directory information from the Open Directory if present. We can easily print the structure with the following code:

foreach my $element (@{$result->{'resultElements'}}) {
  foreach my $key (keys(%$element)) {
    print $key, ': ', $element->{$key}, "\n";

This produces a printout looking like this:

summary: Articles, columns, tools and resources.
title: <b>exploring</b> <b>XML - The Webmaster's Reference on <b>XML</b>:
  Free Tutorials <b>...</b>
directoryCategory: DirectoryCategory=HASH(0x863cca8)
cachedSize: 42k
relatedInformationPresent: 1
directoryTitle: Xploring <b>XML</b>
snippet: Hack into the jungle of this hot new markup language with Exploring XML, a bi-weekly 
  column featuring tutorials, examples and training in XML, XSL style <b>...</b>


In less than ten lines of code we managed to query Google's search engine and print out the results. In the next installment we will pick out the most relevant bits and turn them into a graphical representation using SVG. Hope you will be with me then again, bye for now!

Produced by Michael Claßen

Created: Apr 29, 2002
Revised: Apr 29, 2002