]> git.phdru.name Git - bookmarks_db.git/blobdiff - parse_html/bkmk_ph_htmlparser.py
Fix(Py3): `html.parser` cannot parse bytes
[bookmarks_db.git] / parse_html / bkmk_ph_htmlparser.py
index c0f89b411d688bc99ecaab1a377c80abb36b6891..d11a2ff9fbeab4b5e5ec8daa1c2a7b4205ac63e4 100644 (file)
@@ -91,6 +91,11 @@ class HTMLParser(_HTMLParser):
 def parse_html(html_text, charset=None, log=None):
     if not html_text:
         return None
+    if charset is None and isinstance(html_text, bytes):
+        return None  # html.parser cannot parse bytes
+    if charset and isinstance(html_text, bytes):
+        html_text = html_text.decode(charset)
+
     parser = HTMLParser(charset)
 
     try: