X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=Robots%2Fparse_html.py;h=fd901a8857883a7bc1c5e02d764f76be7f411406;hb=bb2adafe8a51fc3eed213e6c38b05f7b59b81f33;hp=47cbb190527d25c3a1bdb74bf0b694a0fe7df909;hpb=73f38dccb4a11e857ae3497a61089a4ea89cd654;p=bookmarks_db.git diff --git a/Robots/parse_html.py b/Robots/parse_html.py index 47cbb19..fd901a8 100755 --- a/Robots/parse_html.py +++ b/Robots/parse_html.py @@ -77,7 +77,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 +86,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 +109,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