【问题标题】:Dynamic DEPTH_LIMIT as parameter in Scrapy, passed from Scrapyd动态 DEPTH_LIMIT 作为 Scrapy 中的参数,从 Scrapyd 传递
【发布时间】:2023-03-11 22:56:01
【问题描述】:

我目前正在使用 Scrapyd 启动爬虫,并且在 Scrapy App 设置中设置了 DEPTH_LIMIT 设置。

我想知道如何在 Scrapyd 中将 depth_limit 作为参数传递,允许我根据用户的要求为每次不同的抓取“动态地”设置它。

我相信我只能作用于 Scrapy 的蜘蛛和管道。

编辑
感谢@John Smith 的回复,我发现可以将设置传递给scrapyd 的schedule 方法

settings = {
    'unique_id': unique_id,  # unique ID for database instance
    'USER_AGENT': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
    'DEPTH_LIMIT': 1
}

# Schedule a new crawling task from scrapyd
task_id = scrapyd.schedule('default', "spider-name", settings=settings, url=url, domain=domain)

【问题讨论】:

    标签: python scrapy scrapyd


    【解决方案1】:

    除非我误解了您想要指定 DEPTH_LIMIT 的确切时间和地点,否则您可以通过 scrapyd API 调用传递任何 scrapy 设置覆盖:

    curl http://localhost:6800/schedule.json -d project=myproject -d spider=somespider -d setting=DEPTH_LIMIT=5

    http://scrapyd.readthedocs.io/en/stable/api.html#schedule-json

    【讨论】:

    • 是的,谢谢,我编辑了我的帖子以包含完整的答案
    猜你喜欢
    • 1970-01-01
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 2017-09-04
    相关资源
    最近更新 更多