【问题标题】:Scrapyd: how to pass multiple setting values to scrapy serviceScrapyd:如何将多个设置值传递给scrapy服务
【发布时间】:2013-07-30 02:48:09
【问题描述】:

以下是scrapy文档中的示例:

$ curl http://localhost:6800/schedule.json -d project=myproject -d spider=somespider -d setting=DOWNLOAD_DELAY=2 -d arg1=val1

但是如果我想同时设置 DOWNLOAD_DELAY = 2 和 CONCURRENT_REQUESTS = 4,怎么办? 以及如何用 urllib2 做到这一点?

【问题讨论】:

    标签: python urllib2 scrapy urllib web-crawler


    【解决方案1】:

    有两种解决方案。

    第一个,试试这个:

    $ curl http://localhost:6800/schedule.json -d project=myproject -d spider=somespider -d setting=DOWNLOAD_DELAY=2 -d setting=CONCURRENT_REQUESTS=4 -d arg1=val1
    

    第二个:在myproject文件夹(pipelines.py和items.py所在的目录)新建一个名为settings.py的文件。并将所有设置放入其中。这是example。

    【讨论】:

    • 你想用 urllib2 做什么?部署您的项目?也许this 会有所帮助。顺便说一句,我强烈建议您将所有设置放在settings.py。
    • 我想部署我的项目。我有几只蜘蛛。大多数设置都在 setting.py 中。但我想对每个蜘蛛进行一些特殊设置。谢谢,我自己解决了。
    • 嗨@张九洲,你是如何在你的 POST 请求中放置多个设置的?我也很难理解如何放置多个设置。
    【解决方案2】:

    您可以通过将列表传递给设置参数来做到这一点

    import requests
    r = requests.post('http://localhost:6800/schedule.json', data={
            'project': 'your_project',
            'spider': 'your_spider',
            'url': url,
            'setting': ['key1=value1', 'key2=value2']
            })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多