我正在使用以下管道将我的项目导出到 CSV(使用 Scrapy 0.17):
from scrapy import signals
from scrapy.contrib.exporter import CsvItemExporter
class CsvExportPipeline(object):
def __init__(self):
self.files = {}
@classmethod
def from_crawler(cls, crawler):
pipeline = cls()
crawler.signals.connect(pipeline.spider_opened, signals.spider_opened)
crawler.signals.connect(pipeline.spider_closed, signals.spider_closed)
return pipeline
def spider_opened(self, spider):
file = open('/home/ubuntu/SCRAPING/%s_%s.csv' % (self.name, datetime.datetime.now()), 'w+b')
self.files[spider] = file
self.exporter = CsvItemExporter(file)
self.exporter.start_exporting()
def spider_closed(self, spider):
self.exporter.finish_exporting()
file = self.files.pop(spider)
file.close()
def process_item(self, item, spider):
self.exporter.export_item(item)
return item
但是,当我使用此管道时,出现以下错误:
exceptions.AttributeError: 'CsvExportPipeline' object has no attribute 'exporter
'
请建议我缺少什么?