Python IMDbPY – 获取人名
在本文中,我们将了解如何从人员对象中获取人员的备用名称,备用名称基本上是给他们的昵称或舞台名称,即他们被调用的名称,imdb 人员对象的行为类似于字典,因此得到来自人员对象的图像类似于从字典中获取所需信息。
In order to do this we have to do the following –
1. Get the person object with the help of id by using get_person method
2. Get the alternate names from it using result[‘akas’] as keys
3. Print the result
注意:输出将是图像的链接,即字符串数据类型不是实际图像
下面是实现
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# person id
code = "1596350"
# getting person object
actor = ia.get_person(code)
# printing object it prints its name
print(actor)
# getting alternate names
alternate = actor['akas']
# printing
print(alternate)
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# person id
code = "1372788"
# getting person object
actor = ia.get_person(code)
# printing object it prints its name
print(actor)
# getting alternate names
alternate = actor['akas']
# printing
print(alternate)
输出 :
Nawazuddin Siddiqui
['Nawazuddin', 'Novaz', 'Nowaz', 'Nawazuddin Siddique', 'Nawaz Uddin']
另一个例子
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# person id
code = "1372788"
# getting person object
actor = ia.get_person(code)
# printing object it prints its name
print(actor)
# getting alternate names
alternate = actor['akas']
# printing
print(alternate)
输出 :
Shahid Kapoor
['Shahid Kapur', 'Shahid']