0

I'd like to make a kind of homemade algorithm, which from a list of all the movies I have, will return accurate suggestions of movies I haven't seen and I could like. But for that I need to know if IMDBpy can return the "suggestions" part. Indeed, when you search for a movie on the web site, you are given a list of movies matching the kind a movie you searched for.

But I can't find an answer on the doc of IMDBpy. Is there a way to get the suggestions with it ?

JPFrancoia
  • 4,866
  • 10
  • 43
  • 73
  • 1
    Possible duplicate of [Can I retrieve IMDb's movie recommendations for a given movie using IMDbPY?](http://stackoverflow.com/questions/5342329/can-i-retrieve-imdbs-movie-recommendations-for-a-given-movie-using-imdbpy) – snakile May 31 '16 at 19:30

2 Answers2

2

Link!

There's a line in here:

def get_movie_recommendations(self, movieID):

Maybe this can lead you in the right direction.

Inbl
  • 630
  • 2
  • 5
  • 18
1

Since get_movie_recommendations doesn't really work as you wish (e.g. it doesn't return anything for 12 Years a Slave), you could scrape the recommendations with BeautifulSoup.

import bs4
import imdb
import requests

src = requests.get('http://www.imdb.com/title/tt2024544/').text
bs = bs4.BeautifulSoup(src)
recs = [rec['data-tconst'][2:] for rec in bs.findAll('div', 'rec_item')]
print recs

This prints:

['1535109', '0790636', '1853728', '0119217', '2334649', '0095953', '1935179', '2370248', '1817273', '1210166', '0169547', '1907668']

After that you can search for those movies with IMDBpy...

ia = imdb.IMDb()
for rec in recs:
  movie = ia.get_movie(rec)
  print movie.movieID, movie.get('title')

... which outputs:

1535109 Captain Phillips
0790636 Dallas Buyers Club
1853728 Django Unchained
0119217 Good Will Hunting
2334649 Fruitvale Station
0095953 Rain Man
1935179 Mud
2370248 Short Term 12
1817273 The Place Beyond the Pines
1210166 Moneyball
0169547 American Beauty
1907668 Flight
miles82
  • 6,584
  • 38
  • 28
  • Ok thanks :). Of course I want to avoid the use of beautiful soup, but if I can't, I will use it. Do you know why get_recommandations doesn't work ? – JPFrancoia Jan 31 '14 at 21:10
  • get_movie_recommendations fetches info from the movie's /recommendations page which seems to be empty for recent movies. There are recommended movies for e.g. Pulp Fiction (http://www.imdb.com/title/tt0110912/recommendations), but those are not the same ones as those under "People who liked this also liked..." on the movie's main page (the ones I fetch in the example above). See which ones work better for your homemade algorithm :) – miles82 Feb 01 '14 at 00:02