Hmm, looks straighforward enough . . .
>>> import google
>>> google.LICENSE_KEY = '...' # must get your own!
>>> data = google.doGoogleSearch('python')
>>> data.meta.searchTime
0.043221000000000002
>>> dir(data.meta)
['directoryCategories', 'documentFiltering', 'endIndex', 'estimateIsExact',
'estimatedTotalResultsCount', 'searchComments', 'searchQuery', 'searchTime',
'searchTips', 'startIndex']
>>> data.results[0].URL
'http://www.python.org/'
>>> data.results[0].title
'Python Language Website'
Watch what happens when I do it.
[/home/paul]:: python Python 2.2.1 (#1, Jul 27 2002, 20:59:26) [GCC 2.95.3 20010315 (release) [FreeBSD]] on freebsd4 Type "help", "copyright", "credits" or "license" for more information. >>> import google >>> data = google.doGoogleSearch('python') Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.2/site-packages/google.py", line 311, in doGoogleSearch safeSearch, language, inputencoding, outputencoding) File "/usr/local/lib/python2.2/site-packages/SOAP.py", line 3619, in __r_call self.__hd, self.__ma) File "/usr/local/lib/python2.2/site-packages/SOAP.py", line 3539, in __call p, attrs = parseSOAPRPC(r, attrs = 1) File "/usr/local/lib/python2.2/site-packages/SOAP.py", line 2818, in parseSOAPRPC t = _parseSOAP(xml_str, rules = rules) File "/usr/local/lib/python2.2/site-packages/SOAP.py", line 2790, in _parseSOAP parser = xml.sax.make_parser() File "/usr/local/lib/python2.2/xml/sax/__init__.py", line 93, in make_parser raise SAXReaderNotAvailable("No parsers found", None) xml.sax._exceptions.SAXReaderNotAvailable: No parsers found
When you can’t even get copied and pasted code to run, it’s time for bed. Or something.
Of course, I had to try it again, this time on OS X:
/Desktop/pygoogle]:: python
Python 2.2.1 (#1, 10/06/02, 09:00:29)
[GCC Apple cpp-precomp 6.14] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import google
>>> data=google.doGoogleSearch('paul beard seattle')
>>> data.results[0].URL
'http://www.tux.org/hypermail/linux-vortex/2000-Oct/0019.html'
>>> data.results[0].title
'3Com 3c59x/90x (Vortex/Boomerang) Linux Driver Development: [vo'
<sigh>