]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/parse_html_htmlparser.py
Extract charset from "text/html; foo; charset=UTF-8, bar; baz;"
[bookmarks_db.git] / Robots / parse_html_htmlparser.py
index e1a35f1007babbf5a31c93751da082dc3e94156d..cccfe8c7a4b5adab468accbed54287f009f1df72 100644 (file)
@@ -1,7 +1,7 @@
 """
    HTML Parser
 
-   Written by BroytMann. Copyright (C) 1997-2007 PhiloSoft Design
+   Written by BroytMann. Copyright (C) 1997-2008 PhiloSoft Design
 """
 
 from HTMLParser import HTMLParseError
@@ -38,8 +38,8 @@ class HTMLParser(_HTMLParser):
 
       if (not self.charset) and (http_equiv == "content-type"):
          try:
-            # extract charset from "text/html; foo; charset=UTF-8; bar;"
-            self.charset = content.lower().split('charset=')[1].split(';')[0]
+            # extract charset from "text/html; foo; charset=UTF-8, bar; baz;"
+            self.charset = content.lower().split('charset=')[1].split(';')[0].split(',')[0]
             self.meta_charset = 1 # Remember that the charset was retrieved from
                                   # META tag, not from the Content-Type header
          except IndexError:
@@ -73,7 +73,7 @@ class HTMLParser(_HTMLParser):
          self.icon = href
 
 
-def parse_html(filename, charset=None):
+def parse_html(filename, charset=None, log=None):
    infile = open(filename, 'r')
    parser = HTMLParser(charset)