I want to send arguments to spider and get output (json, csv) named accordingly to arguments.
F.e.,
$ scrapy crawl spider_name -a category=category1 -a subcategory=
You can get those parameters from kwargs
of __init__
and use in FEED_URI
like this:
class MySpider(scrapy.Spider):
name = 'my_spider'
custom_settings = {
'FEED_URI' : '%(category)s_%(subcategory)s.json'
}
def __init__(self, *args, **kwargs):
self.category = kwargs.pop('category', '')
self.subcategory = kwargs.pop('subcategory', '')
super(MySpider, self).__init__(*args, **kwargs)
Docs: https://doc.scrapy.org/en/latest/topics/feed-exports.html#storage-uri-parameters