X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fparse_html.py;h=80c7aa89d28efed06db8a598088303f44d2b338b;hb=0e76f1851882b99da63a7c8a9e4cdf0c4a48657f;hp=e676504a9741765fd5f7bc98fb61cd9758b739a2;hpb=2ff00dae6cd629acb517fcb7223b6c17789e9136;p=bookmarks_db.git diff --git a/Robots/parse_html.py b/Robots/parse_html.py index e676504..80c7aa8 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 @@ -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