Parse empty tag with ElementTree
Clash Royale CLAN TAG #URR8PPP Parse empty tag with ElementTree Trying to parse XML using ElementTree. I cannot figure out how to treat empty tags like <tag/> . If the tag is not present at all, .find() returns None and everything is fine. However with <tag> , .find() returns something and the consequent attempt to call text fails with error: <tag/> .find() None <tag> .find() text TypeError: must be str, not NoneType Failing example below. It will fail to parse the line <tl><mpa/></tl> <tl><mpa/></tl> from xml.etree import ElementTree def getStuff(xml_message): message_tree = ElementTree.fromstring(xml_message) ns = {'a': 'http://www.example.org/a', 'b': 'http://www.example.org/b'} tls = message_tree.findall('.//b:tl', namespaces = ns) result, i = (0,)*2 for tl in tls: i += 1 print("Item: " + str(i)) mpa = t...