How do you get a thumbnail of a movie using IMDbPy?

andrewrk picture andrewrk · Nov 9, 2008 · Viewed 8.4k times · Source

Using IMDbPy it is painfully easy to access movies from the IMDB site:

import imdb

access = imdb.IMDb()
movie = access.get_movie(3242) # random ID

print "title: %s year: %s" % (movie['title'], movie['year'])

However I see no way to get the picture or thumbnail of the movie cover. Suggestions?

Answer

Tim Kersten picture Tim Kersten · Nov 9, 2008

Note:

  • Not every movie has a cover url. (The random ID in your example doesn't.)
  • Make sure you're using an up-to-date version of IMDbPy. (IMDb changes, and IMDbPy with it.)

...

import imdb

access = imdb.IMDb()
movie = access.get_movie(1132626)

print "title: %s year: %s" % (movie['title'], movie['year'])
print "Cover url: %s" % movie['cover url']

If for some reason you can't use the above, you can always use something like BeautifulSoup to get the cover url.

from BeautifulSoup import BeautifulSoup
import imdb

access = imdb.IMDb()
movie = access.get_movie(1132626)

page = urllib2.urlopen(access.get_imdbURL(movie))
soup = BeautifulSoup(page)
cover_div = soup.find(attrs={"class" : "photo"})
cover_url = (photo_div.find('img'))['src']
print "Cover url: %s" % cover_url