This commit is contained in:
mutantmonkey
2012-02-08 16:10:37 -05:00
4 changed files with 100 additions and 9 deletions

View File

@@ -20,12 +20,14 @@ class Grab(web.urllib.request.URLopener):
def google_ajax(query):
"""Search using AjaxSearch, and return its JSON."""
if isinstance(query, unicode):
query = query.encode('utf-8')
uri = 'http://ajax.googleapis.com/ajax/services/search/web'
args = '?v=1.0&safe=off&q=' + web.quote(query)
handler = web.urllib.request._urlopener
web.urllib.request._urlopener = Grab()
args = '?v=1.0&safe=off&q=' + web.urllib.quote(query)
handler = web.urllib._urlopener
web.urllib._urlopener = Grab()
bytes = web.get(uri + args)
web.urllib.request._urlopener = handler
web.urllib._urlopener = handler
return web.json(bytes)
def google_search(query):