Python IMDbPY – XML 格式的公司信息
在本文中,我们将了解如何获取 XML 格式的公司信息。可扩展标记语言 (XML) 是一种标记语言,它定义了一组规则,用于以人类可读和机器可读的格式对文档进行编码。 Company 对象包含所有与电影行业相关的公司信息,并在 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 company object with the help of get_company method which requires movie ID
4. Get the XML format value here it will be in string by converting the company object into XML
下面是实现
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# id
code = "0051941"
# getting information
company = ia.get_company(code)
# printing company
print(company)
print("--------------------------------")
# converting company object into XML file
xml_file = company.asXML()
# printing some part of the XML file
print(xml_file[:250])
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# id
code = "0022125"
# getting information
company = ia.get_company(code)
# printing company
print(company)
print("--------------------------------")
# converting company object into XML file
xml_file = company.asXML()
# printing some part of the XML file
print(xml_file[:100])
输出 :
Marvel Studios
--------------------------------
另一个例子
Python3
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# id
code = "0022125"
# getting information
company = ia.get_company(code)
# printing company
print(company)
print("--------------------------------")
# converting company object into XML file
xml_file = company.asXML()
# printing some part of the XML file
print(xml_file[:100])
输出 :
Pixel
--------------------------------