fork download
  1. import xml.etree.ElementTree as ET
  2. html = '<div> <div id="abc 123"></div> <div id="def hhh"></div> <div id="ghi test"></div> </div>'
  3. root = ET.fromstring(html)
  4. try:
  5. print( root.findall(".//div[starts-with(@id, 'def')]") )
  6. except SyntaxError as e:
  7. print e
Success #stdin #stdout 0.01s 7912KB
stdin
Standard input is empty
stdout
invalid predicate