如何阻止蜘蛛进入管道?

2024-09-28 23:44:41 发布

您现在位置:Python中文网/ 问答频道 /正文

@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提出的,但没有得到回应。 谢谢


Tags: close管道objectitemdohowspiderdown
1条回答
网友
1楼 · 发布于 2024-09-28 23:44:41

你的蜘蛛的close_down属性是否创建?因为看起来好像没有

尝试将您的支票改为if "close_down" in self.__dict__:,或者在spider的__init__()方法中添加self.close_down = False。在

相关问题 更多 >