How to make a html text without a root tag (usually it's <html></html>)? To example, for use in CDATA:
<![CDATA[<div class="foo"></div><p>bar</p>]]>
My code:
from lxml import etree
html = etree.Element('root')
etree.SubElement(html, 'div', attrib={'class':'foo'})
etree.SubElement(html, 'p').text='bar'
t = etree.tostring(html)
# '<root><div class="foo"/><p>bar</p></root>'
I would not want to use regex to remove the root tag.