Skip to content

Instantly share code, notes, and snippets.

@subtosilencio
Last active September 1, 2021 18:49
Show Gist options
  • Save subtosilencio/6e27980c72a5455a6d5827840e90045f to your computer and use it in GitHub Desktop.
Save subtosilencio/6e27980c72a5455a6d5827840e90045f to your computer and use it in GitHub Desktop.
import requests
api_key = "XXX" #Google API
cse_id = "XXX" #Search engine ID
q = "information"
def google_query(q, api_key, cse_id):
''' Use Google custom search without google-api-python-client'''
rData = []
url = "https://customsearch.googleapis.com/customsearch/v1"
params = {'key': api_key, 'cx': cse_id ,'q': q}
r = requests.get(url, params=params)
query_results = r.json()
try:
my_results = query_results['items']
for item in my_results:
rData.append((item['htmlTitle'], item['link'], item['htmlSnippet']))
return rData
except:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment