I'm trying to extracting a dataset with the top 20 movies and each genres and actors. For that I'm trying with the following code:
top250 = ia.get_top250_movies()
limit = 20;
index = 0;
output = []
for item in top250:
for genre in top250['genres']:
index += 1;
if index <= limit:
print(item['long imdb canonical title'], ": ", genre);
else:
break;
I'm getting the following error:
Traceback (most recent call last):
File "C:/Users/avilares/PycharmProjects/IMDB/IMDB.py", line 21, in <module>
for genre in top250['genres']:
TypeError: list indices must be integers or slices, not str
I think the object top250 don't have the content genres...
Anyone know how to identify each genre of each movies?
Many thanks!
From the IMDbPY docs:
"It’s possible to retrieve the list of top 250 and bottom 100 movies:"
get_top_250_movies()
returns a list, thus you can't access the movie's genre directly.Here's a solution:
Full working code:
Output: