【问题标题】:Running Scrapy spider from a script with scrapy arguments从带有 scrapy 参数的脚本运行 Scrapy spider
【发布时间】:2014-03-18 02:17:17
【问题描述】:

我在 scrapy 中编写了一个蜘蛛,并且我能够通过 python 脚本成功地运行它。 问题是,在通过scrapy提示运行蜘蛛时,我们提供了“-o ScrapedData.json -t json”之类的参数 我想通过 python 脚本运行“scrapy crawl myspider -o ScrapedData.json -t json”。 非常感谢任何帮助。提前致谢!

【问题讨论】:

  • 不确定我的问题是否正确,但您可能想看看 python subprocess 模块。

标签: python scrapy


【解决方案1】:
  • -o ScrapedData.json 覆盖 FEED_URI 设置
  • -t json 覆盖FEED_FORMAT 设置

(见https://github.com/scrapy/scrapy/blob/master/scrapy/commands/crawl.py#L24

因此,当从脚本运行蜘蛛时,您应该考虑覆盖这两个设置。

【讨论】:

    【解决方案2】:

    你的意思是这样的?

    from scrapy import cmdline
    
    cmdline.execute("scrapy crawl myspider -o ScrapedData.json -t json".split())
    

    【讨论】:

      猜你喜欢
      • 2020-09-26
      • 2015-09-13
      • 2019-12-10
      • 1970-01-01
      • 2015-10-13
      • 1970-01-01
      • 2018-10-04
      • 2015-07-09
      • 1970-01-01
      相关资源
      最近更新 更多