【发布时间】:2013-07-15 04:23:25
【问题描述】:
@Sjaak Trekhaak 在这里有一个“hack”How do I stop all spiders and the engine immediately after a condition in a pipeline is met?,它可以通过在管道中设置一个标志来阻止蜘蛛,然后在解析器方法中调用 CloseSpider。但是我在管道中有以下代码(其中 pdate 和 lastseen 是明确定义的日期时间):
class StopSpiderPipeline(object):
def process_item(self, item, spider):
if pdate < lastseen:
spider.close_down = True
在蜘蛛中
def parse_item(self, response):
if self.close_down:
raise CloseSpider(reason='Already scraped')
我收到错误exceptions.AttributeError: 'SyncSpider' object has no attribute 'close_down',我哪里出错了?这个问题实际上是由@anicake 提出的,但没有得到回应。
谢谢,
【问题讨论】: