Open In App

Python IMDbPY – Movies Information in XML format

In this article we will see how we can get the movies information 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.

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 movie object with the help of get_movie method which requires movie ID
4. Get the XML format value here it will be in string by converting the movie object into XML using asXML method



Below is the implementation




# importing the module
import imdb
   
# creating instance of IMDb
ia = imdb.IMDb()
   
# id
code = "1187043"
   
# getting information
movie = ia.get_movie(code)
   
# printing movie name
print(movie['title'])
  
print("--------------------------------")
  
# converting movie object into XML file
xml_file = movie.asXML()
  
# printing some part of the XML file
print(xml_file[:150])

Output :



3 Idiots
--------------------------------
<?xml version="1.0"?
<!DOCTYPE movie SYSTEM "http://imdbpy.sf.net/dtd/imdbpy68.dtd"

<cast infoset="main"<

Another example




# importing the module
import imdb
   
# creating instance of IMDb
ia = imdb.IMDb()
   
# id
code = "4434004"
   
# getting information
movie = ia.get_movie(code)
   
# printing movie name
print(movie['title'])
  
print("--------------------------------")
  
# converting movie object into XML file
xml_file = movie.asXML()
  
# printing some part of the XML file
print(xml_file[:150])

Output :

Udta Punjab
--------------------------------
<?xml version="1.0"?
<!DOCTYPE movie SYSTEM "http://imdbpy.sf.net/dtd/imdbpy68.dtd"

<cast infoset="main"<

Article Tags :