X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fparse_html.py;h=666c7071fd0072a8249b9e2bf8a0ba4cb4a6e3c6;hb=95b39d3b8b276f64c706c253c6ee643bf93725aa;hp=96022b07335f2ddc487f1eaea87d29f54acd5345;hpb=dc08282f6ed82b219e8b27ae761dd4d45a0f2e50;p=bookmarks_db.git diff --git a/Robots/parse_html.py b/Robots/parse_html.py index 96022b0..666c707 100755 --- a/Robots/parse_html.py +++ b/Robots/parse_html.py @@ -30,7 +30,10 @@ def recode_entities(title, charset): output = [] for part in entity_re.split(title): if entity_re.match(part): - part = unichr(int(part[2:-1])).encode(charset, "replace") + try: + part = unichr(int(part[2:-1])).encode(charset) + except UnicodeEncodeError: + pass # Leave the entity as is output.append(part) return ''.join(output) @@ -83,7 +86,10 @@ def parse_html(filename, charset=None, log=None): except LookupError: if log: log(" unknown charset: `%s' or `%s'" % (parser.charset, current_charset)) - parser.title = recode_entities(title, current_charset) + title = recode_entities(title, current_charset) + title = title.replace('\r', '').replace('\n', ' ').strip() + if log: log(" final title : %s" % title) + parser.title = title return parser