I have the same question as this one, but I struggle to get it working.
I want to get all the values of <itunes:subtitle>
. Not to be confused with the self-closing tag <itunes:subtitle/>
.
This is my XML data in sample.xml
:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<item>
<title>A title</title>
<itunes:subtitle/>
<itunes:subtitle>A subtitle</itunes:subtitle>
</item>
<item>
<title><![CDATA[Another title]]></title>
<itunes:subtitle/>
<itunes:subtitle>Yet another subtitlen</itunes:subtitle>
</item>
</channel>
</rss>
import xml.etree.ElementTree as ET
with open('sample.xml', 'r', encoding='utf8') as f:
tree = ET.parse(f)
root = tree.getroot()
for xml_item in root.iter('item'):
namespaces = {'itunes': 'subtitle'}
print(root.findall('itunes:subtitle', namespaces))
However, this returns empty lists.
[]
[]
I could not find any meaningful help in the other 9-year-old question or elsewhere on Stackoverflow. Please help me out.