Hello,
Perhaps that's a very basic question, but I couldn't find the answer.
lxml.html.fromstring adds implicit parents to the parsed element.
>>> from lxml import html
>>> html.fragment_fromstring("<div>foo</div>").getroottree().getroot()
<Element html at 0x7f8a538c1ec0>
>>> html.fragment_fromstring("<div>foo</div>").getparent()
<Element body at 0x7f8a538c1e10>
>>>
How do I prevent this? ie I want .getparent() to return None and
.getroottree().getroot() to return the top-level element.
Best,
Burak
--
Python : sys.version_info(major=2, minor=7, micro=12,
releaselevel='final', serial=0)
lxml.etree : (3, 6, 4, 0)
libxml used : (2, 9, 4)
libxml compiled : (2, 9, 4)
libxslt used : (1, 1, 29)
libxslt compiled : (1, 1, 29)