From: Oleg Broytman Date: Tue, 1 Dec 2015 16:45:20 +0000 (+0300) Subject: Fix a bug: html_tree may have no childNodes X-Git-Tag: 5.0.0~136 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=256d50445f3fb777a9a2561c7b1f71ccf5ccf6b2;p=bookmarks_db.git Fix a bug: html_tree may have no childNodes --- 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