This works for me. Note. I am using urllib2 for the proxy:
import urllib2 from xml.etree import ElementTree as ET show = 'heroes' season = '4' language = 'en' limit = '1' requestURL = 'http://api.allsubs.org/index.php?' \ + 'search=' + show \ + '+season+' + season \ + '&language=' + language \ + '&limit=' + limit root = ET.parse(urllib2.urlopen(requestURL)).getroot() print root print '\n' items = root.findall('items')[0].findall('item') for item in items: print item.find('title').text
note that findall ('items') finds the βitemsβ tag, what you want to loop (I think) is the βitemβ tag in it, so we find all () of them. In addition, you need to print to get something from python.
Also, if I do this with limit = 2, I get a:
Traceback (most recent call last): File "heros.py", line 18, in <module> root = ET.parse(urllib2.urlopen(requestURL)).getroot() File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 862, in parse tree.parse(source, parser) File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 586, in parse parser.feed(data) File "/usr/lib/python2.6/xml/etree/ElementTree.py", line 1245, in feed self._parser.Parse(data, 0) xml.parsers.expat.ExpatError: not well-formed (invalid token): line 24, column 95
I'm not sure that the XML returning from this API is well-formed - there is no "xml" element at the beginning for starters. I would not trust this ...
Spacedman
source share