Python IMDbPY - 获取人的出生地
在本文中,我们将了解如何从 person 对象中获取人的出生地,imdb person 对象的行为类似于字典,因此,从 person 对象中获取出生地类似于从字典中获取所需信息。
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 birth place from it using result[‘birth info’][‘birth place’] as keys
3. Print the result
下面是实现:
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 birth place
place = actor['birth info']['birth place']
# printing the place
print(place)
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 birth place
place = actor['birth info']['birth place']
# printing the place
print(place)
输出 :
Shahid Kapoor
New Delhi, India
另一个例子:
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 birth place
place = actor['birth info']['birth place']
# printing the place
print(place)
输出 :
Nawazuddin Siddiqui
Budhana, Muzaffarnagar, Uttar Pradesh, India