scrapy redis配置文件setting參數(shù)詳解
scrapy項目 setting.py
#Resis 設(shè)置 #使能Redis調(diào)度器 SCHEDULER = 'scrapy_redis.scheduler.Scheduler' #所有spider通過redis使用同一個去重過濾器 DUPEFILTER_CLASS = 'scrapy_redis.dupefilter.RFPDupeFilter' #不清除Redis隊列、這樣可以暫停/恢復(fù) 爬取 #SCHEDULER_PERSIST = True #SCHEDULER_QUEUE_CLASS ='scrapy_redis.queue.PriorityQueue' #默認(rèn)隊列,優(yōu)先級隊列 #備用隊列。 #SCHEDULER_QUEUE_CLASS ='scrapy_redis.queue.FifoQueue' #先進先出隊列 #SCHEDULER_QUEUE_CLASS ='scrapy_redis.queue.LifoQueue' #后進先出隊列 #最大空閑時間防止分布式爬蟲因為等待而關(guān)閉 #SCHEDULER_IDLE_BEFORE_CLOSE = 10 #將抓取的item存儲在Redis中以進行后續(xù)處理。 ITEM_PIPELINES = { 'scrapy_redis.pipelines.RedisPipeline':300, } # The item pipeline serializes and stores the items in this redis key. #item pipeline 將items 序列化 并用如下key名儲存在redis中 #REDIS_ITEMS_KEY = '%(spider)s:items' #默認(rèn)的item序列化方法是ScrapyJSONEncoder,你也可以使用自定義的序列化方式 #REDIS_ITEMS_SERIALIZER = 'json.dumps' #設(shè)置redis地址 端口 密碼 REDIS_HOST = 'localhost' REDIS_HOST = 6379 #也可以通過下面這種方法設(shè)置redis地址 端口和密碼,一旦設(shè)置了這個,則會覆蓋上面所設(shè)置的REDIS_HOST和REDIS_HOST REDIS_URL = 'redis://root:redis_pass@xxx.xx.xx.xx:6379' #root用戶名,redis_pass:你設(shè)置的redis驗證密碼,xxxx:你的主機ip #你設(shè)置的redis其他參數(shù) Custom redis client parameters (i.e.: socket timeout, etc.) REDIS_PARAMS = {} #自定義的redis客戶端類 #REDIS_PARAMS['redis_cls'] = 'myproject.RedisClient' # If True, it uses redis ``zrevrange`` and ``zremrangebyrank`` operation. You have to use the ``zadd`` # command to add URLS and Scores to redis queue. This could be useful if you # want to use priority and avoid duplicates in your start urls list. #REDIS_START_URLS_AS_SET = False # 默認(rèn)的RedisSpider 或 RedisCrawlSpider start urls key #REDIS_START_URLS_KEY = '%(name)s:start_urls' #redis的默認(rèn)encoding是utf-8,如果你想用其他編碼可以進行如下設(shè)置: #REDIS_ENCODING = 'latin1'
類scrapy_redis.spiders.RedisSpider使spider可以從redis數(shù)據(jù)庫中讀取URL。Redis隊列中的URL將被爬取,如果第一個請求產(chǎn)生更多請求,則spider將處理這些請求,然后再從Redis中獲取另一個URL。
創(chuàng)建spider
from scrapy_redis.spiders import RedisSpider class MySpider(RedisSpider): name = 'myspider' def parse(self, response): # do stuff pass
在redis-cli設(shè)置start_url
redis-cli lpush myspider:start_urls http://google.com
到此這篇關(guān)于scrapy redis配置文件setting參數(shù)詳解的文章就介紹到這了,更多相關(guān)scrapy redis配置setting參數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
django自帶的server 讓外網(wǎng)主機訪問方法
今天小編就為大家分享一篇django自帶的server 讓外網(wǎng)主機訪問方法。具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05詳解Python如何實現(xiàn)壓縮與解壓縮數(shù)據(jù)
當(dāng)數(shù)據(jù)量大的時候,自然而然想到的就是對數(shù)據(jù)進行壓縮,這篇文章主要為大家介紹了Python可以實現(xiàn)壓縮與解壓縮數(shù)據(jù)的相關(guān)模塊的使用,希望對大家有所幫助2024-02-02詳解Pytorch如何利用yaml定義卷積網(wǎng)絡(luò)
大多數(shù)卷積神經(jīng)網(wǎng)絡(luò)都是直接通過寫一個Model類來定義的,這樣寫的代碼其實是比較好懂,也很方便。但是本文將介紹另一個方法:利用yaml定義卷積網(wǎng)絡(luò),感興趣的可以了解一下2022-10-10解決pyecharts在jupyter notebook中使用報錯問題
這篇文章主要介紹了解決pyecharts在jupyter notebook中使用報錯問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-06-06