Sanich
Sanich

Reputation: 1835

Check if google suggests an autocomplete for some term

I want to write a python script that when given a term (string), will checks if google suggest an autocomplete for this term. In other words, it should checks if this is a known term. So I found a google API that can return URLs for a search of a term https://code.google.com/p/pygoogle/. It looks something like:

from pygoogle import pygoogle
g = pygoogle('quake 3 arena')
g.pages = 5
print '*Found %s results*'%(g.get_result_count())
g.get_urls()

But actually, I'm not interested in the URLs. I'm interested only if google suggests an autocomplete for the exact term or not. Any ideas? Thanks!

Upvotes: 0

Views: 218

Answers (2)

taesu
taesu

Reputation: 4570

If you don't have requests lib, install via:

pip install requests

then the code:

import requests

def get_suggestions(s):
        r = requests.get('http://suggestqueries.google.com/complete/search?output=firefox&hl=en&q={}')
        return r.json()[1]

for i in get_suggestions('firefo'):
        print i

Upvotes: 0

cdonts
cdonts

Reputation: 9599

You can use urllib to read suggests in XML format at http://suggestqueries.google.com/...q=quake%203%20arena. Just replace the q parameter and parse content with xml.etree.ElementTree.

Upvotes: 1

Related Questions