]> git.phdru.name Git - bookmarks_db.git/blobdiff - Robots/parse_html_html5.py
Stop tracking a third-party program.
[bookmarks_db.git] / Robots / parse_html_html5.py
index 6255825a3b491d06fb0df847937ed5e638587f36..43e8d74ba957f658ffef276cadb2782ac27e84e5 100644 (file)
@@ -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)