【爬虫学习】TypeError: ExecutionEngine.crawl() got an unexpected keyword argument ‘spider‘

背景:

我在使用Scrapy+scrapy_redis进行分布式爬虫。

Scrapy=2.11.1

scrapy-redis=0.7.3

问题:运行爬虫的时候碰到报错TypeError: ExecutionEngine.crawl() got an unexpected keyword argument 'spider'。

分析:

这个错误是因为Scrapy的ExecutionEngine.crawl()方法不接受spider作为关键字参数。Scrapy-Redis的schedule_next_requests方法尝试将spider作为关键字参数传递给ExecutionEngine.crawl(),但是最新版本的Scrapy中,ExecutionEngine.crawl()并不接受这个参数。

Release notes — Scrapy 2.11.2 documentation

  • Passing a spider argument to the spider_is_idle()crawl() and download() methods of scrapy.core.engine.ExecutionEngine, deprecated in Scrapy 2.6, is no longer supported. (issue 5994issue 5998)

解决:

1、使用scrapy 2.9.0.

2、替换schedule_next_requests 方法

def schedule_next_requests(self):
    """Schedules a request if available"""
    # TODO: While there is capacity, schedule a batch of redis requests.
    for req in self.next_requests():
        # self.crawler.engine.crawl(req, spider=self)
        self.crawler.engine.crawl(req)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值