X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=parse_html%2Fbkmk_ph_htmlparser.py;h=0798467386bda9ab993df160f1d4937b1e1802d9;hb=54576c927fe40509d146212dce65c555148a22c5;hp=295df2bdabe6b9cacf839b3c4bea0a56a70c1d5f;hpb=338c964afba3651bd8fe6318644c0fcabb66cc3b;p=bookmarks_db.git diff --git a/parse_html/bkmk_ph_htmlparser.py b/parse_html/bkmk_ph_htmlparser.py index 295df2b..0798467 100644 --- a/parse_html/bkmk_ph_htmlparser.py +++ b/parse_html/bkmk_ph_htmlparser.py @@ -1,13 +1,11 @@ """HTML Parser using Pythons' HTMLParser This file is a part of Bookmarks database and Internet robot. + """ -__version__ = "$Revision$"[11:-2] -__revision__ = "$Id$"[5:-2] -__date__ = "$Date$"[7:-2] __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 1997-2011 PhiloSoft Design" +__copyright__ = "Copyright (C) 1997-2014 PhiloSoft Design" __license__ = "GNU GPL" __all__ = ['parse_html'] @@ -43,6 +41,9 @@ class HTMLParser(_HTMLParser): http_equiv = value.lower() elif attrname == 'content': content = value + elif (attrname == 'charset') and (not self.charset): + self.charset = value.lower() + self.meta_charset = 1 if (not self.charset) and (http_equiv == "content-type"): try: @@ -79,24 +80,19 @@ class HTMLParser(_HTMLParser): self.icon = href -def parse_html(filename, charset=None, log=None): - infile = open(filename, 'r') +def parse_html(html_text, charset=None, log=None): parser = HTMLParser(charset) - for line in infile: - try: - parser.feed(line) - except (HTMLParseError, HTMLHeadDone): - break - - infile.close() + try: + parser.feed(html_text) + except (HTMLParseError, HTMLHeadDone): + pass try: parser.close() except (HTMLParseError, HTMLHeadDone): pass - if parser.title is None: + if (parser.title is None) and (parser.refresh is None) and (parser.icon is None): return None - return parser