Saturday, December 28, 2024
Google search engine
HomeLanguagesPython IMDbPY – Retrieving actor from the movie details

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_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. 

Python3




# importing the module
import imdb
 
# creating instance of IMDb
ia = imdb.IMDb()
 
# ID
code = "1187043"
 
# getting movie
movie = ia.get_movie(code)
 
# printing movie object
print(movie)
 
print("===============")
 
# getting cast
cast = movie['cast']
 
# actor name from cast
actor = cast[0]
 
# printing actor name
print(actor)


Output :

3 Idiots
===============
Aamir Khan

Another example – 

Python3




# importing the module
import imdb
 
# creating instance of IMDb
ia = imdb.IMDb()
 
# ID
code = "4434004"
 
# getting movie
movie = ia.get_movie(code)
 
# printing movie object
print(movie)
 
print("===============")
 
# getting cast
cast = movie['cast']
 
# actor name from cast
actor = cast[0]
 
# printing actor name
print(actor)


Output :

Udta Punjab
===============
Shahid Kapoor

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments