html with comment that has no parent crashes html_tree_to_text

This commit is contained in:
Sergey Obukhov
2016-08-12 17:40:12 -07:00
parent 7bf37090ca
commit a9719833e0
2 changed files with 14 additions and 1 deletions

View File

@@ -117,7 +117,13 @@ def html_tree_to_text(tree):
style.getparent().remove(style)
for c in tree.xpath('//comment()'):
c.getparent().remove(c)
parent = c.getparent()
# comment with no parent does not impact produced text
if not parent:
continue
parent.remove(c)
text = ""
for el in tree.iter():