scrapy:将代码移动到pipelines.py有exceptions.NameError

时间:2014-08-29 01:52:06

标签: python scrapy

这是我的主要代码

class ProductSpider(Spider):
    name = "email"
    start_urls = []

    def __init__(self):
        ScrapyFileLogObserver(open("spider.log", 'w'), level=log.INFO).start()             
        ScrapyFileLogObserver(open("spider_error.log", 'w'), level=log.ERROR).start()      
        super(ProductSpider, self).__init__()

我想将__init__部分移至pipeline.py def open_spider(self, spider)部分

像这样:

class ShopPipeline(object):
    def open_spider(self, spider):
        ScrapyFileLogObserver(open("spider.log", 'w'), level=log.INFO).start()             
        ScrapyFileLogObserver(open("spider_error.log", 'w'), level=log.ERROR).start()      
        super(ProductSpider, self).__init__()

但我不知道如何修改super(ProductSpider, self).__init__() 错误说exceptions.NameError: global name 'ProductSpider' is not defined

我该怎么编辑呢请指导我谢谢

1 个答案:

答案 0 :(得分:0)

您不需要在super(ProductSpider, self).__init__()中进行open_spider()来电:

class ShopPipeline(object):
    def open_spider(self, spider):
        ScrapyFileLogObserver(open("spider.log", 'w'), level=log.INFO).start()             
        ScrapyFileLogObserver(open("spider_error.log", 'w'), level=log.ERROR).start()      

open_spider()是在蜘蛛打开时调用的方法。