Python IMDbPY – XML 格式的个人信息
在本文中,我们将了解如何获取 XML 格式的人员信息。可扩展标记语言 (XML) 是一种标记语言,它定义了一组规则,用于以人类可读和机器可读的格式对文档进行编码。 Person 对象包含所有与电影行业相关的人的信息,并在 IMDb 数据库中有记录。
In order to get this we have to do the following
1. Import the IMDbPY module
2. Create a instance of IMDB
3. Get the person object with the help of get_person method which requires movie ID
4. Get the XML format value here it will be in string by converting the person object into XML
下面是实现
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# id
code = "1372788"
# getting information
person = ia.get_person(code)
# printing name
print(person['name'])
print("--------------------------------")
# converting person object into XML file
xml_file = person.asXML()
# printing some part of the XML file
print(xml_file[:150])
输出 :
Shahid Kapoor
--------------------------------
另一个例子
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# id
code = "2690647"
# getting information
person = ia.get_person(code)
# printing name
print(person['name'])
print("--------------------------------")
# converting person object into XML file
xml_file = person.asXML()
# printing some part of the XML file
print(xml_file[:250])
输出 :
Pankaj Tripathi
--------------------------------