From 256d50445f3fb777a9a2561c7b1f71ccf5ccf6b2 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 1 Dec 2015 19:45:20 +0300 Subject: [PATCH] Fix a bug: html_tree may have no childNodes --- parse_html/bkmk_ph_html5.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/parse_html/bkmk_ph_html5.py b/parse_html/bkmk_ph_html5.py index 6400d02..6d0d380 100644 --- a/parse_html/bkmk_ph_html5.py +++ b/parse_html/bkmk_ph_html5.py @@ -19,12 +19,13 @@ def parse_html(html_text, charset=None, log=None): 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 -- 2.39.5