#!/usr/bin/python # from http://effbot.org/zone/google-suggest.htm import urllib URI = "http://www.google.com/complete/search?hl=en&js=true&qu=" def suggest(term): # get the javascript dataset text = urllib.urlopen(URI + urllib.quote(term)).read() # pretend it's python text = text.replace("new Array", "new_Array").rstrip().rstrip(";") # simulate the "google suggest" javascript environment dict = {} dict["frameElement"] = None dict["new_Array"] = dict["sendRPCDone"] = lambda *x: x # and run it print text return eval(text, dict) # return zip(*eval(text, dict)[2:4]) print suggest("python")