how to call output filename from scrapy

2020-04-14 01:48发布

scrapy crawl test -o test123.csv

How can I call the Output filename from code i.e I would like to use the filename inputed in terminal in spider_closed function

@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)

标签: python scrapy
1条回答
放我归山
2楼-- · 2020-04-14 02:28

You can use self.settings.attributes["FEED_URI"].value in your spider to get output file name.

查看更多
登录 后发表回答