亚洲国产欧美一区二区三区f,亚洲A∨精品永久无码青草网,亚洲 暴爽 av人人爽日日碰,亚洲AV永久无码精心天堂久久_无码

系統城裝機大師 - 唯一官網:www.outletmksalestore.com!

當前位置:首頁 > 腳本中心 > python > 詳細頁面

scrapy redis配置文件setting參數詳解

時間:2020-11-18來源:www.outletmksalestore.com作者:電腦系統城

scrapy項目 setting.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#Resis 設置
 
#使能Redis調度器
 
SCHEDULER = 'scrapy_redis.scheduler.Scheduler'
 
#所有spider通過redis使用同一個去重過濾器
 
DUPEFILTER_CLASS = 'scrapy_redis.dupefilter.RFPDupeFilter'
 
#不清除Redis隊列、這樣可以暫停/恢復 爬取
 
#SCHEDULER_PERSIST = True
 
#SCHEDULER_QUEUE_CLASS ='scrapy_redis.queue.PriorityQueue' #默認隊列,優先級隊列
#備用隊列。
#SCHEDULER_QUEUE_CLASS ='scrapy_redis.queue.FifoQueue' #先進先出隊列
#SCHEDULER_QUEUE_CLASS ='scrapy_redis.queue.LifoQueue' #后進先出隊列
 
#最大空閑時間防止分布式爬蟲因為等待而關閉
 
#SCHEDULER_IDLE_BEFORE_CLOSE = 10
 
 
#將抓取的item存儲在Redis中以進行后續處理。
 
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'
 
#默認的item序列化方法是ScrapyJSONEncoder,你也可以使用自定義的序列化方式
 
#REDIS_ITEMS_SERIALIZER = 'json.dumps'
 
 
#設置redis地址 端口 密碼
 
REDIS_HOST = 'localhost'
REDIS_HOST = 6379
 
#也可以通過下面這種方法設置redis地址 端口和密碼,一旦設置了這個,則會覆蓋上面所設置的REDIS_HOST和REDIS_HOST
 
 REDIS_URL = 'redis://root:redis_pass@xxx.xx.xx.xx:6379'
 #root用戶名,redis_pass:你設置的redis驗證密碼,xxxx:你的主機ip
 
#你設置的redis其他參數 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
 
# 默認的RedisSpider 或 RedisCrawlSpider start urls key
 
#REDIS_START_URLS_KEY = '%(name)s:start_urls'
 
#redis的默認encoding是utf-8,如果你想用其他編碼可以進行如下設置:
 
#REDIS_ENCODING = 'latin1'

類scrapy_redis.spiders.RedisSpider使spider可以從redis數據庫中讀取URL。Redis隊列中的URL將被爬取,如果第一個請求產生更多請求,則spider將處理這些請求,然后再從Redis中獲取另一個URL。

創建spider

1
2
3
4
5
6
7
8
from scrapy_redis.spiders import RedisSpider
 
class MySpider(RedisSpider):
  name = 'myspider'
 
  def parse(self, response):
    # do stuff
    pass

在redis-cli設置start_url

1 redis-cli lpush myspider:start_urls http://google.com

到此這篇關于scrapy redis配置文件setting參數詳解的文章就介紹到這了

分享到:

相關信息

系統教程欄目

欄目熱門教程

人氣教程排行

站長推薦

熱門系統下載

亚洲国产欧美一区二区三区f,亚洲A∨精品永久无码青草网,亚洲 暴爽 av人人爽日日碰,亚洲AV永久无码精心天堂久久_无码 日本少妇又色又爽又高潮