]> git.phdru.name Git - bookmarks_db.git/blobdiff - parse_html/bkmk_ph_html5.py
Fix(Py3): Fix HTML parsers
[bookmarks_db.git] / parse_html / bkmk_ph_html5.py
index 111e1ed4b4b38360fef84ca41a9276351d0e6c5e..1fabd82166611fcf5c480463296e07390c906be1 100644 (file)
@@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2010-2014 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2010-2023 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 __all__ = ['parse_html']
@@ -17,8 +17,11 @@ from .bkmk_ph_util import HTMLParser
 
 def parse_html(html_text, charset=None, log=None):
     parser = HTML5Parser()
-    html_tree = parser.parse(
-        html_text, encoding=charset, parseMeta=bool(charset))
+    if isinstance(html_text, bytes):
+        html_tree = parser.parse(
+            html_text, encoding=charset, parseMeta=bool(charset))
+    else:
+        html_tree = parser.parse(html_text)
 
     html = None
     if hasattr(html_tree, 'childNodes'):
@@ -73,8 +76,8 @@ def parse_html(html_text, charset=None, log=None):
         if not charset:
             charset = parser.tokenizer.stream.charEncoding[0]
 
-        if title and (charset or meta_charset):
-            title = title.encode(charset or meta_charset)
+        #if title and (charset or meta_charset):
+        #    title = title.encode(charset or meta_charset)
 
         for node in head.childNodes:
             if node.name == 'meta' and \