📜  Python IMDbPY – 获取电影中人物的角色

📅  最后修改于: 2022-05-13 01:54:41.417000             🧑  作者: Mango

Python IMDbPY – 获取电影中人物的角色

在本文中,我们将看到如何获取电影中人物的角色,我们知道电影对象的行为类似于字典。 IMDb 数据库有很多信息,即有关电影中工作人员的详细信息以及该电影中的角色。

下面是实现

Python3
# importing the module
import imdb
 
# creating instance of IMDb
ia = imdb.IMDb()
 
# id
code = "1187043"
 
# getting information
movie = ia.get_movie(code)
 
# printing movie name
cast = movie['cast']
 
# printing actor name
print(cast[0])
 
# getting role
role = cast[0].currentRole
 
# printing role
print(role)


Python3
# importing the module
import imdb
 
# creating instance of IMDb
ia = imdb.IMDb()
 
# id
code = "4434004"
 
# getting information
movie = ia.get_movie(code)
 
# printing movie name
cast = movie['cast']
 
# printing actor name
print(cast[0])
 
# getting role
role = cast[0].currentRole
 
# printing role
print(role)


输出 :

Aamir Khan
Ranchoddas 'Rancho' Shyamaldas Chanchad / Phunsukh Wangdu

另一个例子

Python3

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

输出 :

Shahid Kapoor
Tommy Singh