]> git.phdru.name Git - bookmarks_db.git/blobdiff - parse_html/bkmk_ph_beautifulsoup4.py
Fix(Py3): Fix HTML parsers
[bookmarks_db.git] / parse_html / bkmk_ph_beautifulsoup4.py
index 1095ebce8d510c22df2c9768baed3c27777e1909..6549683edcb094a4282d89a6846aba81286016a0 100644 (file)
@@ -11,18 +11,29 @@ __license__ = "GNU GPL"
 __all__ = ['parse_html']
 
 
+import warnings
+
 from bs4 import BeautifulSoup
 
 from .bkmk_ph_util import HTMLParser
 from compat import string_type
 
+warnings.filterwarnings(
+    'ignore', 'No parser was explicitly specified')
+warnings.filterwarnings(
+    'ignore',
+    "It looks like you're parsing an XML document using an HTML parser.")
+
 universal_charset = "utf-8"
 DEFAULT_CHARSET = "cp1251"  # Stupid default for Russian Cyrillic
 
 
 def _parse_html(html_text, charset):
     try:
-        return BeautifulSoup(html_text, from_encoding=charset)
+        if isinstance(html_text, bytes):
+            return BeautifulSoup(html_text, from_encoding=charset)
+        else:
+            return BeautifulSoup(html_text)
     except TypeError:
         return None