我应该将一些从 json 文件中获取的参数传递给蜘蛛。我已经读过可以通过scrapyd使用 schedule.json 但我不明白如何传递 json 文件。你们有人有经验吗?
问问题
1366 次
2 回答
8
You don't pass the arguments using a JSON file. Scrapyd has a JSON API where you can pass arguments along with it. (e.g. $ curl http://localhost:6800/schedule.json -d project=myproject -d spider=somespider -d myargument="value"
)
You can handle the arguments passed through kwargs
:
class MySpider(Spider):
name = 'somespider'
def __init__(self, *args, **kwargs):
super(MySpider, self).__init__(*args, **kwargs)
self.myargument = kwargs.get('myargument', '')
See http://scrapyd.readthedocs.org/en/latest/api.html for more info.
于 2014-07-08T06:41:20.713 回答
0
我有同样的问题(我想将一个 json 文件传递给蜘蛛以实现一个简单的分布式爬虫系统。
我只是通过将json文件转换为字符串作为scrapyd中的参数来解决它。
于 2015-06-21T14:28:15.317 回答