1

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.

5
  • I wouldn't name a variable json, you may get confused if you try and load the actual module. Commented Jan 4, 2013 at 12:20
  • Why don't you just sign up for Google's search API? It's free. Commented Jan 4, 2013 at 12:22
  • Could you use imdbpy instead? Commented Jan 4, 2013 at 13:11
  • I actully put the movie id into imdbpy later in the script. But imdbpy search_movie seems very unreliable Commented Jan 4, 2013 at 14:07
  • @tsjk There's a known issue in imdbpy 4.9 with search_movie but is fixed in the Mercurial repository. Commented Jan 4, 2013 at 14:43

1 Answer 1

1

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):

  1. Scrap the Google search altogether and use imdbpy.
  2. Use Google Custom Search API to avoid rate limit.

IMDbPY Example

>>> import imdb    
>>> ia = imdb.IMDb()    
>>> movies = ia.search_movie(title='The Hobbit: An Unexpected Journey')    
>>> movies[0].movieID    
'0903624'
Sign up to request clarification or add additional context in comments.

1 Comment

Yes i think iam going with the Google Custom Search API, however haveing some trouble figuering out how to get the information that i need from that so we will see how it goes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.