Python IMDbPY – Retrieving actor from the movie details
In this article we will see how we can retrieve the actors name performed in the movie from the movie information, movie id is the unique id given to each movie by IMDb. We can use search_movie method to search the movies by their name but it gives many movies as they have same names therefore retrieving a movie by its id is a better option.
In order to search a movie by its id we use get_movie method.
Syntax: [to get actors list] cast = movie[‘cast’]
Here movie is the object returned by the get_movie method which act as the dictionary
Below is the implementation.
# importing the moduleimport imdb # creating instance of IMDbia = imdb.IMDb() # IDcode = "1187043" # getting moviemovie = ia.get_movie(code) # printing movie objectprint(movie) print("===============") # getting castcast = movie['cast'] # actor name from casteactor = cast[0] # printing actor nameprint(actor) |
Output :
3 Idiots =============== Aamir Khan
Another example –
# importing the moduleimport imdb # creating instance of IMDbia = imdb.IMDb() # IDcode = "4434004" # getting moviemovie = ia.get_movie(code) # printing movie objectprint(movie) print("===============") # getting castcast = movie['cast'] # actor name from casteactor = cast[0] # printing actor nameprint(actor) |
Output :
Udta Punjab =============== Shahid Kapoor
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course


