See example below:
import bs4 from bs4 import BeautifulSoup XML = """ <TRANSACTION id="T000000000000014727" entrydate="2024-04-20" memo="" commodity="AUD" postdate="2024-04-20"> <SPLITS> <SPLIT id="S0001" number="" reconciledate="" price="1/1" payee="P000035" account="A000831" value="-1499/50" memo="AAA Duracell - 48 pack" action="" bankid="" reconcileflag="2" shares="-1499/50"/> <SPLIT id="S0002" number="" reconciledate="" price="1/1" payee="P000035" account="A000620" value="1499/50" memo="AAA Duracell - 48 pack" action="" bankid="" reconcileflag="0" shares="1499/50"/> </SPLITS> </TRANSACTION> """ soup = BeautifulSoup(XML, 'xml') # only transactions with account A000831 or A000832 for tag in soup.find_all("SPLIT", account=["A000831","A000832"]): print("Anchor: ", tag) print("Value:", tag['value']) print('finished').get() is good for returning defaults in case the attribute is not found .get('attr', 'some-default').