1. 安裝
? ? ? ?pip install scrapy-redis
2. 配置
? ? 在 settings.py 中對(duì) redis 進(jìn)行配置
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活孩,配置在本機(jī)時(shí)為127.0.0.1或localhost'''
REDIS_PORT = 6379 ? ?// 默認(rèn)端口
3. 使用
? ? ? ? 在爬蟲的.py文件中贷祈,爬蟲類要繼承RedisSpider,即:
? ? ? ? ? ? ? ? ? ? ? ? class xxSpider(RedisSpider):
會(huì)將爬取到的數(shù)據(jù)首先存 redis蒋川, 然后再在 redis 中讀取, 類似將 redis 視為一個(gè)隊(duì)列撩笆,不斷的存入不斷拿取捺球。