scrapy crawl test -o test123.csv
如何从代码中调用输出文件名,即我想使用在spider_closed
函数中在终端中输入的文件名
@classmethod
def from_crawler(cls, crawler, *args, **kwargs):
spider = super(MySpider, cls).from_crawler(crawler, *args, **kwargs)
crawler.signals.connect(spider.spider_closed, signal=scrapy.signals.spider_closed)
def spider_closed(self):
#read test123.csv (whatever the filename is)
答案 0 :(得分:0)
您可以在Spider中使用self.settings.attributes["FEED_URI"].value
来获取输出文件名。