Reputation: 43
So i curentlly run this script that i found from http://www.dcortesi.com/blog/2008/05/28/google-ajax-search-api-example-python-code/
import urllib
import simplejson
query = urllib.urlencode({'q' : 'the.hobbit.2012.imdb'})
url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' \
% (query)
search_results = urllib.urlopen(url)
json = simplejson.loads(search_results.read())
results = json['responseData']['results']
for i in results:
if "imdb" in i['url']:
print i['url']
break
What i want is simply to get the first result from google containing imdb. (i need the movie id number)
My problem is, after like 4-6 searches i keep getting for about 15 seconds, then i can do 1 search again.
Traceback (most recent call last):
File "./g", line 9, in <module>
results = json['responseData']['results']
TypeError: 'NoneType' object is unsubscriptable
From what i have read google only allows a certin ammount of searches a day etc. But they should allow more then 10 searches a minute?
What else could be the problem here? Or are there any other better way to search google? I only need the "highest" result that links to imdb.
Upvotes: 1
Views: 1377
Reputation: 17693
Google's Web Search API is deprecated (and rate limit enforcement is being tightened), so you have a couple options (in order of my preference):
>>> import imdb
>>> ia = imdb.IMDb()
>>> movies = ia.search_movie(title='The Hobbit: An Unexpected Journey')
>>> movies[0].movieID
'0903624'
Upvotes: 1