schema.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:taemin 作者: ningirsu 项目源码 文件源码
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', ' ')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号