Last active
September 1, 2021 18:49
-
-
Save subtosilencio/6e27980c72a5455a6d5827840e90045f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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