Hello. Consider the following snippet:
import lxml.html
html = '<div><br />Hello text</div>'
doc = lxml.html.fromstring(html)
text = doc.xpath('//text()')[0]
print lxml.html.tostring(text.getparent())
#prints <br>Hello text
I was expecting to see '<div><br />Hello text</div>'
, because br
can't have nested text and is "self-closed" (I mean />
). How to make lxml
handle it right?