Python IMDbPY – 将系列转换为 XML
在本文中,我们将了解如何获取 XML 格式的剧集演员信息(信息集)。可扩展标记语言 (XML) 是一种标记语言,它定义了一组规则,用于以人类可读和机器可读的格式对文档进行编码。系列对象包含有关在 IMDb 数据库中记录的所有剧集和季节的所有信息。
基本上有两种方法,一种是过滤系列对象,即IMDbPY的具有系列信息的对象,然后将过滤后的数据转换为XML,这种方法冗长而复杂,第二种方法是使用关键字,下面是这样做的方法
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 series object with the help of series ID
4. Get the XML format value here it will be in string by converting the series object into XML with the help of ‘cast’ keyword
下面是实现
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# id
code = "6077448"
# getting information
series = ia.get_movie(code)
# printing title
print(series.data['title'])
print("--------------------------------")
# converting series object's CAST into XML file
xml_cast = series.getAsXML('cast')
# printing some part of the XML file
print(xml_cast[:100])
print(xml_cast[100:200])
输出 :
Sacred Games
--------------------------------
另一个例子
# importing the module
import imdb
# creating instance of IMDb
ia = imdb.IMDb()
# id
code = "6468322"
# getting information
series = ia.get_movie(code)
# printing title
print(series.data['title'])
print("--------------------------------")
# converting series object's CAST into XML file
xml_cast = series.getAsXML('cast')
# printing some part of the XML file
print(xml_cast[:100])
输出 :
Money Heist
--------------------------------