我认为标题是不言自明的。这是代码:
class _BaseSpider(Spider):
name = 'basespider'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._queue = []
@classmethod
def from_crawler(cls, crawler, *args, **kwargs):
spider = super(_BaseSpider, cls).from_crawler(crawler, *args, **kwargs)
crawler.signals.connect(spider._spider_idle, signal=signals.spider_idle)
print('from crawler reached')
return spider
def _spider_idle(self):
print('spider idle reached')
self._schedule_next_request()
raise DontCloseSpider
“从爬网程序已到达” get输出到控制台,但“ spider闲置已到达”则没有。我使用spider_closed
和spider_opened
进行了测试。有了第二个,它确实达到了接收功能。
答案 0 :(得分:0)
我忘记添加reactor.run()
:)更改
crawler = Crawler(CategorySpider)
crawler.crawl()
到
crawler = Crawler(CategorySpider)
crawler.crawl()
reactor.run()
当然可以。