X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=parse_html%2Fbkmk_ph_beautifulsoup.py;fp=parse_html%2Fbkmk_ph_beautifulsoup.py;h=225cb2720f352ae6695a5f1d05e0910e0b118ff0;hb=1249f2d538e9d679421d7bbb59dfac33fad537f4;hp=a0ef6af76a5c78dc061d24acbf95498b44912cec;hpb=b1d58dad799614796d9ee5b27a960cfa820033b1;p=bookmarks_db.git diff --git a/parse_html/bkmk_ph_beautifulsoup.py b/parse_html/bkmk_ph_beautifulsoup.py index a0ef6af..225cb27 100644 --- a/parse_html/bkmk_ph_beautifulsoup.py +++ b/parse_html/bkmk_ph_beautifulsoup.py @@ -4,7 +4,7 @@ This file is a part of Bookmarks database and Internet robot. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2007-2012 PhiloSoft Design" +__copyright__ = "Copyright (C) 2007-2013 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['parse_html'] @@ -110,6 +110,13 @@ def parse_html(filename, charset=None, log=None): else: meta_charset = False + if not meta_charset: + meta = head.find(_find_charset, recursive=False) + if meta: + meta_content = meta.get("charset") + if meta_content: + meta_charset = _charset = meta_content.lower() + if title and (_charset or meta_charset): title = title.encode(_charset or meta_charset) @@ -133,6 +140,9 @@ def _find_contenttype(Tag): return (Tag.name == "meta") and \ (Tag.get("http-equiv", '').lower() == "content-type") +def _find_charset(Tag): + return (Tag.name == "meta") and Tag.get("charset", '') + def _find_refresh(Tag): return (Tag.name == "meta") and \ (Tag.get("http-equiv", '').lower() == "refresh")