Python IMDbPY – 获取电影中人物的角色
在本文中,我们将看到如何获取电影中人物的角色,我们知道电影对象的行为类似于字典。 IMDb 数据库有很多信息,即有关电影中工作人员的详细信息以及该电影中的角色。
In order to the role of the person we have to do the following –
1. Get the movie object with the help of get_movie method
2. Get the cast details from the movie object
3. Get the role of desired person with the help of currentRole method
4. Show the result
下面是实现
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