I'm using the following code to extract links from google search to use for getting text that includes the keyword.
# -*- coding: utf-8 -*-
import json
import urllib.request, urllib.parse
def showsome(searchfor,rzs,start,lang):
query = urllib.parse.urlencode({'q': searchfor})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&{0}&q=gates&rsz={1}&start={2}&hl={3}'.format(query,rzs,start,lang)
search_response = urllib.request.urlopen(url)
search_results = search_response.read().decode("utf8")
results = json.loads(search_results)
data = results['responseData']
print(data)
hits = data['results']
print(hits)
#print('Top %d hits:' % len(hits))
listofLinks = []
for h in hits:
#print(' ', h['url'])
listofLinks.append(h['url'])
return(listofLinks)
showsome('manger','1','4','fr')
However, in intervals I'm getting the following error:
Traceback (most recent call last):
File "C:\Python33\code\htmlDraft.py", line 27, in
print(showsome('manger','4','1','fr'))
File "C:\Python33\code\htmlDraft.py", line 17, in showsome
hits = data['results']
TypeError: 'NoneType' object is not subscriptable
Which means something to the effect that he doesn't receive data. Is that because google is blocking me? I thought I was using their ajax API.