Calling Google's Custom Search API via Python

user353829 picture user353829 · Dec 21, 2010 · Viewed 8.5k times · Source

I am writing in Python a module that will query Google's Custom Search API and return all listings of domain 'example.com'

I Have been reading instructions at https://code.google.com/apis/customsearch/v1/getting_started.html and am a little stumped at the moment.

Are my assumptions listed below correct?

For example, to search for results that has 'example.com' in the URL, the query is:

*'https://www.googleapis.com/customsearch/v1?key=my_key&cx=017576662512468239146:omuauf_lfve&q=site:example.com'*

*key=my_key:* value of key given by google

cx=017576662512468239146: name of the search engine (google)? Is this correct?

*omuauf_lfve:* I have no idea what this is

q=site:example.com: This should return all results with 'example.com'; e.g. www.a.example.com, b.example.com, example .com

Answer

ffriend picture ffriend · Sep 7, 2011

Though this question is quite old and the author doesn't seem to be too responsive, Google still highly ranks this page and many people may come here, so I post my answer.

Searching with Google Custom Search is described in this answer to similar question.

Parameters are as follows:

key - yes, it is API key for your Google account. To obtain it go to APIs console, switch on Custom Search API on Services tab and find actual API key on API Access tab.

cx - yes again, it is search engine unique code. Note, that this code is of form "123456:abcdef", so "omuauf_lfve" is part of this code, not the other param.

q - actual search query. "site:example.com" is part of Google's query language. See search tips for details.