X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;ds=sidebyside;f=Robots%2Fparse_html_beautifulsoup.py;fp=Robots%2Fparse_html_beautifulsoup.py;h=8f82d249669df7a7d79cc0a203103596f4284936;hb=5240de604c92063107e41cd00c6b363498d65fa6;hp=dc61a3305a3c0509562cfa9df56ccb88d550dc60;hpb=2ff00dae6cd629acb517fcb7223b6c17789e9136;p=bookmarks_db.git diff --git a/Robots/parse_html_beautifulsoup.py b/Robots/parse_html_beautifulsoup.py index dc61a33..8f82d24 100644 --- a/Robots/parse_html_beautifulsoup.py +++ b/Robots/parse_html_beautifulsoup.py @@ -70,36 +70,29 @@ def parse_html(filename, charset=None, log=None): if root is None: return None - try: - html = root.html - except AttributeError: - if log: log("No HTML in root") - html = root - + html = root.html if html is None: html = root - try: - head = html.head - except AttributeError: - if log: log("No HEAD in HTML") - head = html - + head = html.head if head is None: head = html # Some sites put TITLE in HTML without HEAD - try: - title = head.title.string.encode(_charset) - except AttributeError: - title = '' # HEAD but no TITLE - - if (not title) and (head is not html): + title = head.title + if (title is None) and (html is not head): # Some sites put TITLE in HTML outside of HEAD + title = html.title - try: - title = html.title.string.encode(_charset) - except AttributeError: - title = '' # no TITLE in HTML too + if title is None: + # Lookup TITLE in the root + title = root.title + + if title is None: + title = '' + elif title.string: + title = title.string.encode(_charset) + else: + title = str(title) meta = head.find(_find_contenttype, recursive=False) if meta: