X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=Robots%2Fparse_html_html5.py;h=43e8d74ba957f658ffef276cadb2782ac27e84e5;hb=b47c320c38663d1a6d5def2c2d34febcd075be89;hp=6255825a3b491d06fb0df847937ed5e638587f36;hpb=f10b20785d3f5ba0b42ff2ca6e13efb194fdd4cc;p=bookmarks_db.git diff --git a/Robots/parse_html_html5.py b/Robots/parse_html_html5.py index 6255825..43e8d74 100644 --- a/Robots/parse_html_html5.py +++ b/Robots/parse_html_html5.py @@ -38,6 +38,17 @@ def parse_html(filename, charset=None, log=None): icon = None if head: + for node in head.childNodes: + if node.name == 'title': + if node.childNodes: + title = node.childNodes[0].value + break + else: + title = '' + + if title is None: + return None + for node in head.childNodes: if node.name == 'meta' and \ ('http-equiv' in node.attributes) and \ @@ -52,18 +63,10 @@ def parse_html(filename, charset=None, log=None): else: break - for node in head.childNodes: - if node.name == 'title': - if node.childNodes: - title = node.childNodes[0].value - break - else: - title = '' - if not charset: charset = parser.tokenizer.stream.charEncoding[0] - if title and (charset or meta_charset): + if charset or meta_charset: title = title.encode(charset or meta_charset) for node in head.childNodes: @@ -80,4 +83,16 @@ def parse_html(filename, charset=None, log=None): icon = node.attributes['href'] break + else: + for node in html.childNodes: + if node.name == 'title': + if node.childNodes: + title = node.childNodes[0].value + break + else: + title = '' + + if title is None: + return None + return HTMLParser(charset, meta_charset, title, refresh, icon)