X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fparse_html.py;h=66400b5fd4b711106d9f44a866ecaceece972f8d;hb=5b927f4924fdb9fccb91e5b4477960e9c6dc0797;hp=47cbb190527d25c3a1bdb74bf0b694a0fe7df909;hpb=73f38dccb4a11e857ae3497a61089a4ea89cd654;p=bookmarks_db.git diff --git a/Robots/parse_html.py b/Robots/parse_html.py index 47cbb19..66400b5 100755 --- a/Robots/parse_html.py +++ b/Robots/parse_html.py @@ -2,7 +2,7 @@ """ HTML Parsers wrapper - Written by BroytMann. Copyright (C) 1997-2008 PhiloSoft Design + Written by Broytman. Copyright (C) 1997-2008 PhiloSoft Design """ import codecs @@ -34,7 +34,9 @@ def recode_entities(title, charset): for part in entity_re.split(title): if part not in ("&", "<", ">", """) and \ entity_re.match(part): - part = unichr(name2codepoint.get(part[1:-1], part)).encode(charset) + _part = name2codepoint.get(part[1:-1], None) + if _part is not None: + part = unichr(_part).encode(charset) output.append(part) title = ''.join(output) @@ -77,7 +79,7 @@ def parse_html(filename, charset=None, log=None): if log: log("Parser %s.%s failed, trying next one." % (p.__module__, p.__name__)) converted_title = title = parser.title - if not parser.charset: + if title and (not parser.charset): try: unicode(title, "ascii") except UnicodeDecodeError: @@ -86,7 +88,7 @@ def parse_html(filename, charset=None, log=None): if parser.charset: parser.charset = parser.charset.lower().replace("windows-", "cp") - if parser.charset and ( + if title and parser.charset and ( (parser.charset <> universal_charset) or ((not charset) or (charset <> parser.charset))): try: @@ -109,11 +111,12 @@ def parse_html(filename, charset=None, log=None): else: if log: log(" title : %s" % title) - final_title = recode_entities(converted_title, universal_charset) - parts = [s.strip() for s in final_title.replace('\r', '').split('\n')] - final_title = ' '.join([s for s in parts if s]) - if log and (final_title <> converted_title): log(" final title : %s" % final_title) - parser.title = final_title + if title: + final_title = recode_entities(converted_title, universal_charset) + parts = [s.strip() for s in final_title.replace('\r', '').split('\n')] + final_title = ' '.join([s for s in parts if s]) + if log and (final_title <> converted_title): log(" final title : %s" % final_title) + parser.title = final_title return parser