X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=parse_html%2Fbkmk_ph_beautifulsoup4.py;h=060f0786d473c17de36ad073c05632c06f30c35d;hb=a9f7112dec88b4136ad5ef7c6876e5c9ef14745c;hp=6549683edcb094a4282d89a6846aba81286016a0;hpb=8f6a9a521d21c398e100c254eda47d55498cbb54;p=bookmarks_db.git diff --git a/parse_html/bkmk_ph_beautifulsoup4.py b/parse_html/bkmk_ph_beautifulsoup4.py index 6549683..060f078 100644 --- a/parse_html/bkmk_ph_beautifulsoup4.py +++ b/parse_html/bkmk_ph_beautifulsoup4.py @@ -39,6 +39,8 @@ def _parse_html(html_text, charset): def parse_html(html_text, charset=None, log=None): + if not html_text: + return None root = _parse_html(html_text, charset) if root is None: return None @@ -67,9 +69,12 @@ def parse_html(html_text, charset=None, log=None): else: parts = [] for part in title: - if not isinstance(part, string_type): - part = part.decode() - parts.append(part.strip()) + #if not isinstance(part, string_type): + # part = part.decode() + if part.strip: + parts.append(part.strip()) + else: + parts.append(' ') # Skip tags, they're usually `
` title = ''.join(parts) meta = head.find(_find_contenttype, recursive=False) @@ -134,6 +139,7 @@ def _find_refresh(Tag): def _find_icon(Tag): - return (Tag.name == "link") and \ - (Tag.get_attribute_list("rel", '')[0].lower() - in ('icon', 'shortcut icon')) + if Tag.name != "link": + return False + rel = ' '.join(Tag.get_attribute_list("rel", '')) + return rel in ('icon', 'shortcut icon')