import xml.etree.ElementTree as ET
html = '<div> <div id="abc 123"></div> <div id="def hhh"></div> <div id="ghi test"></div> </div>'
root = ET.fromstring(html)
try:
print( root.findall(".//div[starts-with(@id, 'def')]") )
except SyntaxError as e:
print e
aW1wb3J0IHhtbC5ldHJlZS5FbGVtZW50VHJlZSBhcyBFVApodG1sID0gJzxkaXY+IDxkaXYgaWQ9ImFiYyAxMjMiPjwvZGl2PiA8ZGl2IGlkPSJkZWYgaGhoIj48L2Rpdj4gPGRpdiBpZD0iZ2hpIHRlc3QiPjwvZGl2PiA8L2Rpdj4nCnJvb3QgPSBFVC5mcm9tc3RyaW5nKGh0bWwpCnRyeToKCXByaW50KCByb290LmZpbmRhbGwoIi4vL2RpdltzdGFydHMtd2l0aChAaWQsICdkZWYnKV0iKSApCmV4Y2VwdCBTeW50YXhFcnJvciBhcyBlOgoJcHJpbnQgZQ==