if log: log("Parser %s.%s failed, trying next one." % (p.__module__, p.__name__))
converted_title = title = parser.title
- if not parser.charset:
+ if title and (not parser.charset):
try:
unicode(title, "ascii")
except UnicodeDecodeError:
if parser.charset:
parser.charset = parser.charset.lower().replace("windows-", "cp")
- if parser.charset and (
+ if title and parser.charset and (
(parser.charset <> universal_charset) or
((not charset) or (charset <> parser.charset))):
try:
else:
if log: log(" title : %s" % title)
- final_title = recode_entities(converted_title, universal_charset)
- parts = [s.strip() for s in final_title.replace('\r', '').split('\n')]
- final_title = ' '.join([s for s in parts if s])
- if log and (final_title <> converted_title): log(" final title : %s" % final_title)
- parser.title = final_title
+ if title:
+ final_title = recode_entities(converted_title, universal_charset)
+ parts = [s.strip() for s in final_title.replace('\r', '').split('\n')]
+ final_title = ' '.join([s for s in parts if s])
+ if log and (final_title <> converted_title): log(" final title : %s" % final_title)
+ parser.title = final_title
return parser
# Lookup TITLE in the root
title = root.title
- if title is None:
- title = ''
- elif title.string:
- title = title.string.encode(_charset)
- else:
- parts = []
- for part in title:
- if not isinstance(part, basestring):
- part = unicode(part)
- parts.append(part.strip())
- title = ''.join(parts).encode(_charset)
+ if title is not None:
+ if title.string:
+ title = title.string.encode(_charset)
+ else:
+ parts = []
+ for part in title:
+ if not isinstance(part, basestring):
+ part = unicode(part)
+ parts.append(part.strip())
+ title = ''.join(parts).encode(_charset)
meta = head.find(_find_contenttype, recursive=False)
if meta:
if hasattr(object, "moved") or hasattr(object, "error"):
continue
- if hasattr(object, "real_title"):
+ if hasattr(object, "real_title") and (object.real_title is not None):
unquoted_title = unquote_title(quote_title(object.real_title))
unquoted_name = unquote_title(object.name)
if unquoted_name <> unquoted_title: