fork(2) download
  1. import lxml.etree
  2. html = '<div> <div id="abc 123"></div> <div id="def hhh"></div> <div id="ghi test"></div> </div>'
  3. root = lxml.etree.fromstring(html)
  4.  
  5. print root.xpath(".//div[starts-with(@id, 'def')]")[0].attrib
Success #stdin #stdout 0.02s 15280KB
stdin
Standard input is empty
stdout
{'id': 'def hhh'}