X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=parse_html%2Fbkmk_ph_beautifulsoup4.py;h=6549683edcb094a4282d89a6846aba81286016a0;hb=8c04e58972d1c58ab82250df093c3d503eed4fe2;hp=33a2e18dd65376c1794c94d22b41c174212a24cb;hpb=968bbee3279fdea70161ed595146f11ec69c57ea;p=bookmarks_db.git diff --git a/parse_html/bkmk_ph_beautifulsoup4.py b/parse_html/bkmk_ph_beautifulsoup4.py index 33a2e18..6549683 100644 --- a/parse_html/bkmk_ph_beautifulsoup4.py +++ b/parse_html/bkmk_ph_beautifulsoup4.py @@ -11,10 +11,18 @@ __license__ = "GNU GPL" __all__ = ['parse_html'] +import warnings + from bs4 import BeautifulSoup from .bkmk_ph_util import HTMLParser -from ..compat import string_type +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 @@ -22,7 +30,10 @@ 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 @@ -84,12 +95,12 @@ def parse_html(html_text, charset=None, log=None): if meta_content: meta_charset = _charset = meta_content.lower() - if title and (_charset or meta_charset): - try: - title = title.encode(_charset or meta_charset) - except LookupError: - title = title.encode(universal_charset) - _charset = universal_charset + #if title and (_charset or meta_charset): + # try: + # title = title.encode(_charset or meta_charset) + # except LookupError: + # title = title.encode(universal_charset) + # _charset = universal_charset meta = head.find(_find_refresh, recursive=False) if meta: