>>> s = \' < 20 \' >>> import lxml.html >>> tree = lxml.html.fromstring(s) >>> lxml.etree.tostring(tree
Your < should actually be <, since < is sorta like a 'reserved character' in html. Then it should work.
<