def get_title(html):
"""
Get the title element from a HTML document
:param str html: The html to parse
:Example:
>>> Link.get_title("xxxx<title>Title</title>xxxx")
'Title'
>>> print(Link.get_title("xxxx<>Title</title>xxxx"))
None
"""
bs = BeautifulSoup(html, 'html.parser', parse_only=SoupStrainer('title'))
title = bs.find("title")
if not title:
return None
if not title.string:
return None
return title.string.strip().replace('\n', ' ')
评论列表
文章目录