Python编写通用的网络爬虫用于新闻聚合类应用,类似Flipboard

2024-10-04 01:28:25 发布

您现在位置:Python中文网/ 问答频道 /正文

最近,我被分配到我的大学,一个新闻聚合项目。我发现Flipboard是一个非常有趣和病毒式的新闻聚合应用程序。为了实现这一点,我正在构建一个网络爬虫,它将抓取网站,获取最近的新闻和帖子。我正在看一篇关于Gizmod的帖子

Is the scraper universal/generic, or are there customer scrapers for certain sites?

Doll: It is mostly universal/generic. However, we can limit the amount of content displayed on a site-specific basis. We already try to do this with some sites that publish extremely abbreviated RSS feeds- even though we aren't using RSS directly, we attempt to achieve display parity with their feed.

我非常熟悉从单个网站获取数据的过程。但我不确定如何从多个网站和博客获取数据,这些网站和博客的结构完全不同。在

我目前正在使用python2.7、urllib2和beauthoulsoup对单个网站进行爬网。在

问题:

我想知道,我怎样才能实现仅仅通过一个通用爬虫从成千上万个网站获取数据的目标?在


Tags: theto项目网站with新闻sitesuniversal
2条回答

我建议创建一个大的Spider类,然后为各个站点创建子类。我写了一个类似问题的简短回答here on stackoverflow。在

我也做过类似的事情,尽管我对python和googlefu有基本的了解,但我教会了我如何制作一个更高级的用户会嘲笑的脚本。但是嘿,我用它很管用,不会留下太多的脚印。在

我做了几个函数,这些函数使用'request'来获取站点,并使用'beauthulsoup'根据我在Chrome中使用inspector对站点进行反向工程的结构来解析各个站点。 当脚本运行时,它运行所有函数,从而获取我想要的信息。在

相关问题 更多 >