Redis的安装、配置

2016-12-08  本文已影响0人  byewinter

1. 安装

       pip install scrapy-redis

2. 配置

    在 settings.py 中对 redis 进行配置

SCHEDULER = "scrapy_redis.scheduler.Scheduler"

SCHEDULER_PERSIST = Ture

SCHEDULER_QUEUE_CLASS = "scrapy_redis.queue.SpiderPriorityQueue"

REDIS_URL = None    //目前可有可无

REDIS_HOST = '127.0.0.1'   //'''此处是 redis 的ip,配置在本机时为127.0.0.1或localhost'''

REDIS_PORT = 6379    // 默认端口

3. 使用

        在爬虫的.py文件中,爬虫类要继承RedisSpider,即:

                        class xxSpider(RedisSpider):

会将爬取到的数据首先存 redis, 然后再在 redis 中读取, 类似将 redis 视为一个队列,不断的存入不断拿取。

上一篇下一篇

猜你喜欢

热点阅读