X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=parse_html%2Fbkmk_ph_beautifulsoup4.py;h=6549683edcb094a4282d89a6846aba81286016a0;hb=5d420bb788898217727d24814c8259e419bf8773;hp=fbd54ff9cfd207c583d5119ba06c20faf23f9d4d;hpb=8a33ee42d7f8edff076734eba8c1718da8127b22;p=bookmarks_db.git diff --git a/parse_html/bkmk_ph_beautifulsoup4.py b/parse_html/bkmk_ph_beautifulsoup4.py index fbd54ff..6549683 100644 --- a/parse_html/bkmk_ph_beautifulsoup4.py +++ b/parse_html/bkmk_ph_beautifulsoup4.py @@ -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 @@ -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: