cnn_news_scraper.py 文件源码

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

项目:TapNews 作者: AaronTL 项目源码 文件源码
def extract_news(news_url):
    # Fetch html
    session_requests = requests.session()
    response = session_requests.get(news_url, headers=getHeaders())

    news = {}

    try:
        # Parse html
        tree = html.fromstring(response.content)
        # Extract information
        news = tree.xpath(GET_CNN_NEWS_XPATH)
        news = ''.join(news)
    except Exception as e:
        print # coding=utf-8
        return {}

    return news
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号