Python IMDbPY – 从搜索到的人中获取人名
在本文中,我们将了解如何从搜索到的人员中获取人员 id,人员 id 基本上是赋予每个人的唯一 id,某些人的名称可以相同,但 id 会不同。我们使用search_person
方法来获取同名的人。
为了获取人员 ID,我们使用personID
方法。
Syntax : persons[0].personID
Here persons is the list of person returned by search_person and persons[0] refer to first element in list
Argument : It takes no argument.
Return : It return string which is Person ID
下面是实现。
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# name
name = "Ayushmann Khurrana"
# searching the name
search = ia.search_person(name)
# loop for printing the name and id
for i in range(len(search)):
# getting the id
id = search[i].personID
# printing it
print(search[i]['name'] + " : " + id )
输出 :
Ayushmann Khurrana : 4731677
另一个例子
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# name
name = "Pankaj Tripathi"
# searching the name
search = ia.search_person(name)
# loop for printing the name and id
for i in range(len(search)):
# getting the id
id = search[i].personID
# printing it
print(search[i]['name'] + " : " + id )
输出 :
Pankaj Tripathi : 2690647
Pankaj Tripathi : 11337375
Sankalp Raj Tripathi : 9704712