6.8. Programming Assignment 4 – Web Based APIs

You are to develop a simple Python program that will prompt the user to enter the name of a movie or TV show and then it will display a list of the actors in the movie. You will get the data by sending a request, per the published API, to IMDbPY. Although the data returned may be in a variety of formats (JSON might be simplest), please have it return XML data. You may want experiment with other ways to retrieve the data using the API, but also use XML. XML is important enough that a little practice working with it seems important. Then pass the data to a parser such as BeautifulSoup, xml.dom.minidom or xml.etree.ElementTree. If you use BeautifulSoup, see also Parsing XML with BeautifulSoup.

Due to the requirement of BeautifulSoup to use lxml to parse XML, xml.dom.minidom may be easiest to use. The lxml module is difficult to install in Windows. See the xml.dom.minidom documentation.

IMDbPY may be installed with easy_install.

Here is some starter code:

from imdb import IMDb
import xml.dom.minidom

ia = IMDb()

the_matrix = ia.get_movie('0133093')
folks = the_matrix.getAsXML( 'cast' )
dom = xml.dom.minidom.parseString(folks)
people = dom.getElementsByTagName('person')
for peep in people:
    for node in peep.childNodes:
        if node.nodeName == u'name':
            for n in node.childNodes:
                if n.nodeType == n.TEXT_NODE:
                    print n.data

Previous topic

6.7. API based Web Programming

Next topic

6.9. XML and XML-RPC

This Page