Programming the Google Web API with Python

Programming the Google Web API with Python is simple and clean, as these scripts and interactive examples demonstrate.

Programming to the Google Web API from Python is a piece of cake, thanks to Mark Pilgrim’s PyGoogle wrapper module ( PyGoogle abstracts away much of the underlying SOAP, XML, and request/response layers, leaving you free to spend your time with the data itself.

PyGoogle Installation

Download a copy of PyGoogle and follow the installation instructions ( Assuming all goes to plan, this should be nothing more complex than:

% python install

Alternately, if you want to give this a whirl without installing PyGoogle or don’t have permissions to install it globally on your system, simply put the included and files into the same directory as the script itself.

The Code

#!/usr/bin/python # # A typical Google Web API Python script using Mark Pilgrim's # PyGoogle Google Web API wrapper # [] # Usage: python <query> import sys, string, codecs # Use the PyGoogle module import google # Grab the query from the command-line if sys.argv[1:]: query = sys.argv[1] else: sys.exit('Usage: python <query>') # Your Google API developer's key google.LICENSE_KEY = 'insert key here' # Query Google data = google.doGoogleSearch(query) # Teach standard ...

Get Google Hacks now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.