Google Search API For Python

Remember a few years ago when google had an API allowing for searches from within an application?  Then, they decided to ditch the project.  I wrote an implementation of the old google search api, but with one modification, I put no limitation on the results.  Thank you, Andy Pavlo for your help with this project.

You’ll need:

Beautiful Soup
Mechanize

Download Google Search API For Python

Sample implementation:

>>> from Google import Google, search
>>> results = search(’blackcodeseo.com’, 3)
>>> for result in results:
…     print ‘Title: %s’ % (result.title())
…     print ‘Url: %s’ % (result.url())
…     print ‘Description: %s’ % (result.description())
…     print

Title: Black Code SEO
Url: http://blackcodeseo.com/
Description: Oct 29, 2008 … Black Code SEO. Programatically Automating SEO … Download BlackCodeSeo Navigator. Run python setup.py install …

Title: Have A Question?
Url: http://blackcodeseo.com/have-a-question/
Description: If you have any questions about anything, you can reach me at matt@blackcodeseo. com and I will be happy to reply. Your questions may be posted on the site …

Title: SpiderMonkey « Didier Stevens
Url: http://blog.didierstevens.com/programs/spidermonkey/
Description: The exact post is http://blackcodeseo.com/python-spidermonkey-navigator/. Comment by Matt — Wednesday 29 October 2008 @ 20:56. Thanks. …

>>>

1 Comment

Ben says: 10 February 2009 - 4:14 pm

Hi –

I’m getting an error when testing this as in the example you provided:

Traceback (most recent call last):
File “”, line 1, in
File “Google.py”, line 116, in search
googles += getPageData(html)
File “Google.py”, line 75, in getPageData
description = str(tag(’div’)[0])
IndexError: list index out of range

Any ideas?

Leave a comment