简体   繁体   中英

Running Scrapy spider from a script with scrapy arguments

I have written a spider in scrapy & I'm successfully able to run it via a python script. The problem is, while running a spider via scrapy prompt we supply agruments like " -o ScrapedData.json -t json " I want to run "scrapy crawl myspider -o ScrapedData.json -t json " via python script. Any help is highly appreciated. Thanks in advance!

  • -o ScrapedData.json overrides the FEED_URI setting
  • and -t json overrides the FEED_FORMAT setting

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

So, when running your spider from a script, you should look at overriding these 2 settings.

You mean like this?

from scrapy import cmdline

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM