Open In App

Python IMDbPY – Getting Series Genres as XML

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how we can get the series genres information(info-set) in the XML format. Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The series object contains all the information about all the episodes and seasons that have been recorded at the IMDb database. 
Genre is any form or type of communication in any mode with socially-agreed-upon conventions developed over time. In series, there are various types of genres for example comedy, horror, action, etc.
 

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 ‘genres’ keyword 
 

Below is the implementation 
 

Python3




# 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 GENRES into XML file
xml = series.getAsXML('genres')
 
# printing some part of the XML file
print(xml[:100])


Output : 
 

Money Heist
--------------------------------
<genres infoset="main"<itemAction</item<item Crime</item<item Mystery</item<itemThriller</item

Another example 
 

Python3




# 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 GENRES into XML file
xml = series.getAsXML('genres')
 
# printing some part of the XML file
print(xml[:100])


Output : 
 

Sacred Games
--------------------------------
<genres infoset="main"<item Action</item<item Crime</item<item Drama</item<item Thriller</item<

 



Last Updated : 16 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads