According to xml.etree.ElementTree
documentation - XPath support:
This module provides limited support for XPath expressions for
locating elements in a tree. The goal is to support a small subset of
the abbreviated syntax; a full XPath engine is outside the scope of
the module.
You may need third-part library like lxml
to use XPath.
Example:
>>> import lxml.etree
>>>
>>> url = 'http://services.tvrage.com/myfeeds/episode_list.php?key=ag6txjP0RH4m0c8sZk2j&sid=2930'
>>> tree = lxml.etree.parse()
>>> tree.xpath("/Show/Episodelist/Season[@no='%s']/episode/seasonnum/text()" % 1)
['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
UPDATE
To use lxml.etree.ElementTree
, the xpath should be slightly modified:
>>> import urllib
>>> import xml.etree.ElementTree as ET
>>>
>>> f = urllib.urlopen(url)
>>> tree = ET.parse(f)
>>> [e.text for e in tree.findall("./Episodelist/Season[@no='%s']/episode/seasonnum" % 1)]
['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']