-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle.py
More file actions
28 lines (23 loc) · 906 Bytes
/
google.py
File metadata and controls
28 lines (23 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from googleapiclient.discovery import build
import simplejson as json
import tldextract
#import pprint
my_api_key = "AIzaSyDrO3fpX1AMOhwBS_nTvU2sUHAgqobnrFU"
my_cse_id = "008760540502611867558:q1tp0tmtixw"
def google_search(search_term, api_key, cse_id, **kwargs):
service = build("customsearch", "v1", developerKey=api_key)
res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
return res['items']
def getbase(url):
ext = tldextract.extract(url)
return '.'.join(ext[1:3])
results = google_search('flash', my_api_key, my_cse_id, num=10)
for result in results:
#pprint.pprint(result)
for key, value in result.items():
#print("%s -> %s"%(key,value))
if key.encode('utf-8').decode('utf-8') == "formattedUrl":
print(("%s --> %s")%(getbase(value),value))
# res = json.loads(result.decode('utf-8'))
# data = res['formatedurl']
# print(data)