cinemagoer icon indicating copy to clipboard operation
cinemagoer copied to clipboard

Recommendations returning empty

Open richardtml opened this issue 3 years ago • 2 comments

Hi, your library is really good, thanks for the work.

I want to get the movies under "More Like This", however, I've got an empty result with the code below. I saw #241 , but the fix is not working for me.

IMDbPY 2021.04.18, Python 3.8 and Ubuntu 20.04

from imdb import IMDb
ia = IMDb()
ia.get_movie_recommendations("0133093")

richardtml avatar Dec 06 '21 04:12 richardtml

Can confirm, I'm also having the same issue.

kaangiray26 avatar Jan 25 '22 09:01 kaangiray26

Since I couldn't find any working solutions, here's what I've written instead:

import re
from bs4 import BeautifulSoup
import requests

def has_recommendation(tag):
    return tag.has_attr('href') and tag['href'].startswith('/title/tt')

def get_recommendations(id):
    html = requests.get(f'https://www.imdb.com/title/tt{id}/').content
    soup = BeautifulSoup(html, 'html.parser')
    recs = soup.find("section", attrs={"data-testid": "MoreLikeThis"})
    return [re.findall("title/tt(.......)", obj['href'])[0] for obj in recs.find_all(has_recommendation)]

@alberanid I'm no familiar with your code but maybe this can help you fix the code if there's a problem.

kaangiray26 avatar Jan 25 '22 10:01 kaangiray26