【问题标题】:Crawl only content from multiple different Websites仅抓取来自多个不同网站的内容
【发布时间】:2019-04-16 18:57:05
【问题描述】:

目前我正在做一个项目,我想分析来自不同博客、杂志等的不同文章,这些文章在他们的网站上在线发布。

因此,我已经使用 Python 构建了一个 Webcrawler,它将每篇新文章都以 html 格式获取。

现在重点是,我想分析纯内容(只有文章,没有 cmets 或推荐等),但我无法访问此内容,没有定义正则表达式,从 html 响应中提取内容我明白了。每个来源的正则表达式不是替代品,因为我有大约 100 个不同的文章来源。

我曾尝试使用库 html2text 来提取内容,但是该库仅将纯 html 转换为 markdown,因此仍然存在 cmets 或推荐之类的东西,我必须手动删除。

任何想法,我该如何面对这个问题?

【问题讨论】:

    标签: python web-scraping web-crawler data-analysis


    【解决方案1】:

    为了获取主要文章文本并忽略无关文本,您必须为特定网页编写代码或设计一些启发式方法来识别和提取文章内容。

    幸运的是,现有的库可以解决这个问题。

    Newspaper 是一个 Python 3 库:

    from newspaper import Article
    url = 'http://fox13now.com/2013/12/30/new-year-new-laws-obamacare-pot-guns-and-drones/'
    article = Article(url)
    article.download()
    print(article.text)
    

    您可能还想查看类似的库,例如 python-readabilitypython-goose

    from goose import Goose
    url = 'http://edition.cnn.com/2012/02/22/world/europe/uk-occupy-london/index.html?hpt=ieu_c2'
    g = Goose()
    article = g.extract(url=url)
    print(article.cleaned_text)
    

    【讨论】:

    • 您还知道不专门研究报纸文章的图书馆吗?我正在抓取公司项目
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 2011-03-12
    相关资源
    最近更新 更多