在Python中进行Web爬网的最佳预构建库是什么?

Jay*_*ens 0 python web-crawler

我需要在本地抓取并存储以供将来分析有限的网站列表的内容.我基本上想要在所有页面中啜饮并按照所有内部链接来获取整个公开的网站.

是否有现有的免费图书馆让我在那里?我见过奇尔卡特,但这是为了报酬.我只是在这里寻找基线功能.思考?建议?


完全重复:任何人都知道我可以使用的基于python的网络爬虫吗?

nos*_*klo 7

使用Scrapy.

它是一个基于扭曲的Web爬虫框架.仍处于重大发展阶段,但已经有效.有很多好吃的东西:

  • 内置支持解析HTML,XML,CSV和Javascript
  • 用于使用图像(或任何其他媒体)抓取项目并同时下载图像文件的媒体管道
  • 通过使用中间件,扩展和管道插入您自己的功能,支持扩展Scrapy
  • 广泛的内置中间件和扩展,用于处理压缩,缓存,cookie,身份验证,用户代理欺骗,robots.txt处理,统计信息,爬网深度限制等
  • 交互式刮擦shell控制台,对开发和调试非常有用
  • 用于监视和控制机器人的Web管理控制台
  • Telnet控制台,用于对Scrapy进程进行低级访问

通过在返回的HTML上使用XPath选择器提取有关今天在mininova torrent网站中添加的所有torrent文件的信息的示例代码:

class Torrent(ScrapedItem):
    pass

class MininovaSpider(CrawlSpider):
    domain_name = 'mininova.org'
    start_urls = ['http://www.mininova.org/today']
    rules = [Rule(RegexLinkExtractor(allow=['/tor/\d+']), 'parse_torrent')]

    def parse_torrent(self, response):
        x = HtmlXPathSelector(response)
        torrent = Torrent()

        torrent.url = response.url
        torrent.name = x.x("//h1/text()").extract()
        torrent.description = x.x("//div[@id='description']").extract()
        torrent.size = x.x("//div[@id='info-left']/p[2]/text()[2]").extract()
        return [torrent]
Run Code Online (Sandbox Code Playgroud)