@Sjaak Trekhaak在这里有一个“hack”How do I stop all spiders and the engine immediately after a condition in a pipeline is met?,它可以通过在管道中设置一个标志来阻止蜘蛛,然后在解析器方法中调用CloseSpider。不过,我在管道中有以下代码(pdate和lastseen是定义良好的datetime):
class StopSpiderPipeline(object):
def process_item(self, item, spider):
if pdate < lastseen:
spider.close_down = True
还有蜘蛛
^{pr2}$我出错了exceptions.AttributeError: 'SyncSpider' object has no attribute 'close_down'
,哪里出错了?这个问题实际上是由@anicake提出的,但没有得到回应。
谢谢
你的蜘蛛的
close_down
属性是否创建?因为看起来好像没有尝试将您的支票改为
if "close_down" in self.__dict__:
,或者在spider的__init__()
方法中添加self.close_down = False
。在相关问题 更多 >
编程相关推荐