X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fparse_html.py;h=fd901a8857883a7bc1c5e02d764f76be7f411406;hb=bb2adafe8a51fc3eed213e6c38b05f7b59b81f33;hp=678f3e2dae49d9961c07e040aeca2ec7e8e832aa;hpb=2f06deff348d6a49ba7f8f0d941e0bd3445e6418;p=bookmarks_db.git diff --git a/Robots/parse_html.py b/Robots/parse_html.py index 678f3e2..fd901a8 100755 --- a/Robots/parse_html.py +++ b/Robots/parse_html.py @@ -32,7 +32,7 @@ num_entity_re = re.compile("(&#[0-9]+;)") def recode_entities(title, charset): output = [] for part in entity_re.split(title): - if part not in ("&", "<", ">", ""e;") and \ + if part not in ("&", "<", ">", """) and \ entity_re.match(part): part = unichr(name2codepoint.get(part[1:-1], part)).encode(charset) output.append(part) @@ -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 @@ -130,7 +131,6 @@ if __name__ == '__main__': else: sys.exit("Usage: %s filename [charset]" % sys.argv[0]) - parser = parse_html(filename, universal_charset, - log=lambda s: sys.stdout.write(s + '\n')) + parser = parse_html(filename, charset, log=lambda s: sys.stdout.write(s + '\n')) print " refresh:", parser.refresh print " icon :", parser.icon