Google AJAX Search API Example Python Code
For whatever reason, there aren’t many examples on the net of Python code that can be used with the Google AJAX Search API. I’m not really sure why this is and perhaps I’m missing something, but for future reference here’s some sample python code.
#!/usr/bin/python
import urllib
import simplejson
query = urllib.urlencode({'q' : 'damon cortesi'})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' \
% (query)
search_results = urllib.urlopen(url)
json = simplejson.loads(search_results.read())
results = json['responseData']['results']
for i in results:
print i['title'] + “: ” + i['url']
10 Comments so far
Leave a comment
Thank you!
your example was _very_ useful today
Searched about half an hour someone who could give me a soap-api key… until i found your blog.
By Wiedion 05.28.08 8:26 am
thank you very much for this code.
I looked for something similar for a long time.
I still can’t figure out why there is only four results returned. I tried to find a clue about this limitation but i didn’t find any. Could you tell me if you have any idea about this or a place where i could find more information.
By Celon 06.10.08 7:07 am
@Celon For whatever reason, the API returns 4 results at a time and only up to 16 total results for a search. You have to pass an additional “start” parameter to get the rest of the results.
You can find some more info here:
http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje
By Damonon 06.10.08 2:38 pm
Where do I get the python library simplejson - Is there an easy way to install it?
Thanks
By moorthyon 06.17.08 11:14 am
@moorthy If you’re running a recent version of python and have setuptools installed, you may be able to just run ‘easy_install simplejson’.
I did run into a problem with this on my MacBook, though, and had to specify an older version to install. I’ll see if I can find the link.
By Damonon 06.17.08 1:04 pm
Downloading from http://pypi.python.org/pypi/simplejson and running through
$ python setup.py build
$ sudo python setup.py install
worked for me.
By Damonon 07.13.08 5:19 pm
thanks a whole lot
By anonymouson 07.29.08 9:27 pm
I’m a superstar rated iReported over at CNN and I just posted an iReport on your TweetStats and TweetCloud service. Hope you like it… repost and let folks know. Maybe it’ll be featured in broadcast.
Tell folks to Twitter Rick Sanchez (CNN) about it.
http://twitter.com/ricksanchezcnn
By Dan Hollingson 08.24.08 4:45 pm
Oh, the iReport URL about TweetStas and Tweetclouds is here:
http://www.ireport.com/docs/DOC-65484
.
By Dan Hollingson 08.24.08 4:47 pm
This is great info. Thanks folks.
By Joe Dorocakon 08.26.08 12:46 pm
Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>