I'm trying to parse an xml file using Python which has the following line
<Stat Type="total_pass">37</Stat>
I would like to get the 37 value giving a certain attribute - in this case it would be total_pass
.
I'm trying to parse an xml file using Python which has the following line
<Stat Type="total_pass">37</Stat>
I would like to get the 37 value giving a certain attribute - in this case it would be total_pass
.
Below
import xml.etree.ElementTree as ET
xml = '<r><Stat Type="total_pass">37</Stat><Stat Type="other">33</Stat></r>'
root = ET.fromstring(xml)
stat_with_total_pass = root.find(".//Stat[@Type='total_pass']")
print(stat_with_total_pass.text)
output
37