From: Oleg Broytman Date: Mon, 3 Mar 2008 14:30:54 +0000 (+0000) Subject: Test meta charset by looking in META HTTP-Equiv. X-Git-Tag: v4.5.3~189 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=8226e19cbea0c03e35a3827929514bf5dc350e92;p=bookmarks_db.git Test meta charset by looking in META HTTP-Equiv. git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@187 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23 --- diff --git a/Robots/parse_html_beautifulsoup.py b/Robots/parse_html_beautifulsoup.py index c7263fe..c45af2b 100644 --- a/Robots/parse_html_beautifulsoup.py +++ b/Robots/parse_html_beautifulsoup.py @@ -83,6 +83,13 @@ def parse_html(filename, charset=None): except AttributeError: title = '' # no TITLE in HTML too + meta = head.find(_find_contenttype, recursive=False) + if meta: + __charset = meta.get("content").lower().split('charset=')[1].split(';')[0] + meta_charset = _charset == __charset + else: + meta_charset = False + meta = head.find(_find_refresh, recursive=False) if meta: refresh = meta.get("content") @@ -95,7 +102,11 @@ def parse_html(filename, charset=None): else: icon = None - return BSoupParser(_charset, _charset != charset, title, refresh, icon) + return BSoupParser(_charset, meta_charset, title, refresh, icon) + +def _find_contenttype(Tag): + return (Tag.name == "meta") and \ + (Tag.get("http-equiv", '').lower() == "content-type") def _find_refresh(Tag): return (Tag.name == "meta") and \