關於在使用scrapy-redis分佈式踩過的那些坑:

本身的案列:win7上安裝ubuntu (win7做爲slaver,ubuntu做爲master )redis

 

修改配置文件redis.conf數據庫

1)打開配置文件把下面對應的註釋掉

# bind 127.0.0.1 ubuntu

2)Redis默認不是以守護進程的方式運行,能夠經過該配置項修改,設置爲no

daemonize no網絡

3)保護模式

protected-mode no dom

關鍵的一步:ubuntu終端命令中重啓redis服務的時候以下操做:ide

redis-server redis.confurl

在win7上安裝RedisDesktopManage查看ubuntur  Redis數據庫 (鏈接方法:完成以上1,2,3便可鏈接 注意:ubuntu的網絡適配器要選擇橋接模式。)spa

 

在編寫爬蟲的時候:server

發現這樣寫域名的範圍會報錯(在ubuntu中push url後爬蟲沒有爬取數據):blog

#動態域範圍的獲取
def __init__(self, *args, **kwargs):
# Dynamically define the allowed domains list.
domain = kwargs.pop('domain', '')
self.allowed_domains = filter(None, domain.split(','))
super(MySpider, self).__init__(*args, **kwargs)

而這樣寫不會報錯:

allowed_domains = ["xxx.com"]

在爬蟲的settings.py中指明主機地址以及端口號

如:

REDIS_HOST = 'x.x.x.x' 主機地址(ubuntu IP地址)
REDIS_PORT = 6379

相關文章
相關標籤/搜索