scrapy的redis安装和配置

来源:互联网 发布:爱思助手有没有mac版 编辑:程序博客网 时间:2024/05/17 01:07

在定向爬虫的制作过程中,使用分布式爬取技术可以显著提高爬取效率。而 Redis 配合 Scrapy 是实现分布式爬取的基础。

Redis 是一个高性能的 Key-Value 数据库,它把数据保存在内存里。因此可以有非常快的数据读写速度。

scrapy-redis 的安装

pip install scrapy-redis

easy_install scrapy-redis

下载

http://redis.io/download

版本推荐

stable 3.0.2

运行redis

redis-server redis.conf

清空缓存

redis-cli flushdb

scrapy配置redis

settings.py配置redis

SCHEDULER = "scrapy_redis.scheduler.Scheduler"

SCHEDULER_PERSIST = True

SCHEDULER_QUEUE_CLASS = 'scrapy_redis.queue.SpiderPriorityQueue'

REDIS_URL = None # 一般情况可以省去

REDIS_HOST = '127.0.0.1' # 也可以根据情况改成 localhost

REDIS_PORT = 6379

在scrapy中使用scrapy-redis

spider 继承RedisSpider

class tempSpider(RedisSpider)  

name = "temp"

redis_key  = ''temp:start_url"

0 0
原创粉丝点击