I need to check the existence of certain tags in an XML file before parsing it; I'm using Element Tree in Python. Reading here, I tried writing this:
tgz_xml = f"https://www.ncbi.nlm.nih.gov/pmc/utils/oa/oa.fcgi?id=PMC8300416"
response = urllib.request.urlopen(tgz_xml).read()
tree = ET.fromstring(response)
for OA in tree.findall('OA'):
records = OA.find('records')
if records is None:
print('records missing')
else:
print('records found')
I need to check if the "records" tag exists. I don't get an error, but this doesn't print out anything. What did I do wrong? Thank you!