There are 2 distinct issues here, both handled by other questions.
First:
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
See live: https://ideone.com/PfpjYz
Error is "cannot use absolute path on element" - this is handled by Python - ElementTree- cannot use absolute path on element
Second issue, when using relative elements, you get a different error:
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
See live: https://ideone.com/BNc7My
Error has changed "invalid predicate" - see xpath-support - starts-with is not there
See: Python XPath SyntaxError: invalid predicate for possible solutions.
Finally, you can use a different xml library, or work around the limitations of this one.
import lxml.etree
root = lxml.etree.fromstring(html)
print root.xpath(".//div[starts-with(@id, 'def')]")[0].attrib
See online: https://ideone.com/Ie1j8F
Note: this is still a duplicate question, and should be closed as such, but this is to long to fit into an comment.