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.

tsjk
  • 43
  • 1
  • 7
  • I wouldn't name a variable `json`, you may get [confused](http://stackoverflow.com/questions/712791/json-and-simplejson-module-differences-in-python) if you try and load the actual module. – YXD Jan 04 '13 at 12:20
  • Why don't you just sign up for Google's search API? It's free. – Blender Jan 04 '13 at 12:22
  • Could you use [`imdbpy`](http://imdbpy.sourceforge.net/) instead? – Bryan Jan 04 '13 at 13:11
  • I actully put the movie id into imdbpy later in the script. But imdbpy search_movie seems very unreliable – tsjk Jan 04 '13 at 14:07
  • @tsjk There's a known issue in imdbpy 4.9 with `search_movie` but is fixed in the [Mercurial repository](https://bitbucket.org/alberanid/imdbpy). – Bryan Jan 04 '13 at 14:43

1 Answers1

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'
Bryan
  • 17,112
  • 7
  • 57
  • 80
  • 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. – tsjk Jan 04 '13 at 15:35