Из документов IMDbPY :
"Возможно получить список из 250 лучших и 100 нижних фильмов:"
>>> top = ia.get_top250_movies()
>>> top[0]
<Movie id:0111161[http] title:_The Shawshank Redemption (1994)_>
>>> bottom = ia.get_bottom100_movies()
>>> bottom[0]
<Movie id:4458206[http] title:_Code Name: K.O.Z. (2015)_>
get_top_250_movies()
возвращает список, поэтому вы не можете напрямую получить доступ к жанру фильма.
Вот решение:
# Iterate through the movies in the top 250
for topmovie in top250:
# First, retrieve the movie object using its ID
movie = ia.get_movie(topmovie.movieID)
# Print the movie's genres
for genre in movie['genres']:
print(genre)
Полный рабочий код:
import imdb
ia = imdb.IMDb()
top250 = ia.get_top250_movies()
# Iterate through the first 20 movies in the top 250
for movie_count in range(0, 20):
# First, retrieve the movie object using its ID
movie = ia.get_movie(top250[movie_count].movieID)
# Print movie title and genres
print(movie['title'])
print(*movie['genres'], sep=", ")
Вывод:
The Shawshank Redemption
Drama
The Godfather
Crime, Drama
The Godfather: Part II
Crime, Drama
The Dark Knight
Action, Crime, Drama, Thriller
12 Angry Men
Crime, Drama
Schindler's List
Biography, Drama, History
The Lord of the Rings: The Return of the King
Action, Adventure, Drama, Fantasy
Pulp Fiction
Crime, Drama
The Good, the Bad and the Ugly
Western
Fight Club
Drama
The Lord of the Rings: The Fellowship of the Ring
Adventure, Drama, Fantasy
Forrest Gump
Drama, Romance
Star Wars: Episode V - The Empire Strikes Back
Action, Adventure, Fantasy, Sci-Fi
Inception
Action, Adventure, Sci-Fi, Thriller
The Lord of the Rings: The Two Towers
Adventure, Drama, Fantasy
One Flew Over the Cuckoo's Nest
Drama
Goodfellas
Crime, Drama
The Matrix
Action, Sci-Fi
Seven Samurai
Adventure, Drama
City of God
Crime, Drama