"""Search Google from the command lineThis program is part of "Dive Into Python", a free Python book forexperienced programmers. Visit http://diveintopython.org/ for thelatest version."""__author__="Mark Pilgrim (mark@diveintopython.org)"__version__="$Revision: 1.2 $"__date__="$Date: 2004/05/20 18:53:59 $"__copyright__="Copyright (c) 2004 Mark Pilgrim"__license__="Python"fromSOAPpyimportWSDL# you'll need to configure these two values;# see http://www.google.com/apis/WSDLFILE='/path/to/copy/of/GoogleSearch.wsdl'APIKEY='YOUR_GOOGLE_API_KEY'_server=WSDL.Proxy(WSDLFILE)defsearch(q):"""Search Google and return list of {title, link, description}"""results=_server.doGoogleSearch(APIKEY,q,0,10,False,"",False,"","utf-8","utf-8")return[{"title":r.title.encode("utf-8"),"link":r.URL.encode("utf-8"),"description":r.snippet.encode("utf-8")}forrinresults.resultElements]if__name__=='__main__':importsysforrinsearch(sys.argv[1])[:5]:printr['title']printr['link']printr['description']print