parser = HTML5Parser()
html_tree = parser.parse(html_text, encoding=charset, parseMeta=bool(charset))
- for node in html_tree.childNodes:
- if (node.name == 'html') and (node.type != 3): # Skip DocType element
- html = node
- break
- else:
- html = None
+ html = None
+ if hasattr(html_tree, 'childNodes'):
+ for node in html_tree.childNodes:
+ # Skip DocType element
+ if (node.name == 'html') and (node.type != 3):
+ html = node
+ break
if not html:
return None