]> git.phdru.name Git - bookmarks_db.git/commitdiff
If there is HEAD but no TITLE - return empty title.
authorOleg Broytman <phd@phdru.name>
Tue, 8 Jan 2008 11:20:40 +0000 (11:20 +0000)
committerOleg Broytman <phd@phdru.name>
Tue, 8 Jan 2008 11:20:40 +0000 (11:20 +0000)
git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@155 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23

Robots/parse_html_beautifulsoup.py

index d73e4c313a62a67570eb190dac14d5198499ef1b..62ef27709a67d27a91c7a86d220e6214d7f94888 100644 (file)
@@ -58,19 +58,24 @@ def parse_html(filename, charset=None):
    finally:
       infile.close()
 
-   _charset = root.originalEncoding
    try:
-      title = root.html.head.title.string.encode(_charset)
+      head = root.html.head
    except AttributeError:
       return None
 
-   meta = root.html.head.find(_find_refresh, recursive=False)
+   _charset = root.originalEncoding
+   try:
+      title = head.title.string.encode(_charset)
+   except AttributeError:
+      return '' # HEAD but no TITLE
+
+   meta = head.find(_find_refresh, recursive=False)
    if meta:
       refresh = meta.get("content")
    else:
       refresh = None
 
-   meta = root.html.head.find(_find_icon, recursive=False)
+   meta = head.find(_find_icon, recursive=False)
    if meta:
       icon = meta.get("href")
    else: