How can I programmatically using the Google Python client library do an advanced search with Google custom search API search engine in order to return a list of first n
links based in some terms and parameters of an advanced search I queried?.
I tried to check the documentation(I did not found any example), and this answer. However, the latter did not worked, since currently there is no support for the AJAX API. So far I tried this:
from googleapiclient.discovery import build
import pprint
my_cse_id = "test"
def google_search(search_term, api_key, cse_id, **kwargs):
service = build("customsearch", "v1",developerKey="<My developer key>")
res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
return res['items']
results = google_search('dogs', my_api_key, my_cse_id, num=10)
for result in results:
pprint.pprint(result)
And this:
import pprint
from googleapiclient.discovery import build
def main():
service = build("customsearch", "v1",developerKey="<My developer key>")
res = service.cse().list(q='dogs').execute()
pprint.pprint(res)
if __name__ == '__main__':
main()
Thus, any idea of how to do and advanced search with google's search engine API?. This is how my credentials look at google console:
urls
that containthe best dog food
inenglish
in theUK
. – Workday