簡體   English   中英

如何阻止蜘蛛進入管道?

[英]How to stop a spider from pipeline?

@Sjaak Trekhaak在這里有一個“ hack”,在滿足管道中的條件后,如何立即停止所有蜘蛛和引擎? 通過在管道中設置一個標志,然后在解析器方法中調用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__:是否為if "close_down" in self.__dict__:或在蜘蛛的__init__()方法中添加self.close_down = False

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM