news.py 文件源码

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

项目:GoogleBot 作者: MarcoBuster 项目源码 文件源码
def get(query='', lang='en'):
    d = feedparser.parse('https://news.google.it/news?cf=all&hl={l}&query={q}&pz=1&ned={l}&output=rss'
                         .format(l=lang, q=query))
    text = d.feed.title
    for e in d.entries:
        soup = bs4.BeautifulSoup(e.description, 'html.parser')
        news = soup.find_all('font', size="-1")[1].get_text()
        title = e.title.rsplit('-')[0]
        author = e.title.rsplit('-')[1]
        title, author = title.rstrip().lstrip(), author.rstrip().lstrip()
        link = e.link
        text += (
            '\n?? <b>{title}</b> • <a href="{link}">{author}</a>'
            '\n{news}\n'.format(title=title, news=news, link=link, author=author)
        )

    return text
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号