gpt4 book ai didi

python - 如何阻止管道中的蜘蛛?

转载 作者:太空宇宙 更新时间:2023-11-04 06:13:01 25 4
gpt4 key购买 nike

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

最佳答案

您的蜘蛛的close_down 属性是否已创建?因为它看起来不像。

尝试将检查更改为 if "close_down"in self.__dict__: 或在蜘蛛的 __init__() 中添加 self.close_down = False > 方法。

关于python - 如何阻止管道中的蜘蛛?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17646739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com