]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/parse_html_beautifulsoup.py
Always log guessed charset even if it's utf-8.
[bookmarks_db.git] / Robots / parse_html_beautifulsoup.py
index c7263fe64b478769e931ab978e4e382ed2233d3c..11db56371b0df277dd957484f782e54624721e40 100644 (file)
@@ -83,6 +83,17 @@ def parse_html(filename, charset=None):
       except AttributeError:
          title = '' # no TITLE in HTML too
 
+   meta = head.find(_find_contenttype, recursive=False)
+   if meta:
+      try:
+         __charset = meta.get("content").lower().split('charset=')[1].split(';')[0]
+      except IndexError: # No charset in the META Content-Type
+         meta_charset = False
+      else:
+         meta_charset = _charset == __charset
+   else:
+      meta_charset = False
+
    meta = head.find(_find_refresh, recursive=False)
    if meta:
       refresh = meta.get("content")
@@ -95,7 +106,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 \