我想向spider发送参数并获得相应命名为参数的输出(json,csv)
F.E.,
$ scrapy crawl spider_name -a category = category1 -a subcategory = subcategory1
我想得到:
category1_subcategory1.json(或csv,没关系)。
我的意思是我需要json名称作为蜘蛛的参数。
class MySpider(scrapy.Spider):
name = 'my_spider'
# how can I get to this place ?
customs_settings = {
'FEED_URI' : 'some_name.json'
}
def __init__(self, category, subcategory, *args, **kwargs):
super(MySpider, self).__init__(*args, **kwargs)
self.category = category
self.subcategory = subcategory
答案 0 :(得分:1)
您可以从kwargs
的{{1}}获取这些参数,并在__init__
中使用,如下所示:
FEED_URI
文档:https://doc.scrapy.org/en/latest/topics/feed-exports.html#storage-uri-parameters