From e94bd8187ca7bdf21c391186d9da8425014db439 Mon Sep 17 00:00:00 2001 From: Jae-Myoung Yu Date: Tue, 25 Sep 2012 09:38:00 +0900 Subject: [PATCH] add options -o and -t to the runspider command copy the codes from commands/crawl.py to commands/runspider.py --- scrapy/commands/runspider.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scrapy/commands/runspider.py b/scrapy/commands/runspider.py index 183855029..cac7d3d98 100644 --- a/scrapy/commands/runspider.py +++ b/scrapy/commands/runspider.py @@ -38,6 +38,10 @@ class Command(ScrapyCommand): ScrapyCommand.add_options(self, parser) parser.add_option("-a", dest="spargs", action="append", default=[], metavar="NAME=VALUE", \ help="set spider argument (may be repeated)") + parser.add_option("-o", "--output", metavar="FILE", \ + help="dump scraped items into FILE (use - for stdout)") + parser.add_option("-t", "--output-format", metavar="FORMAT", default="jsonlines", \ + help="format to use for dumping items with -o (default: %default)") def process_options(self, args, opts): ScrapyCommand.process_options(self, args, opts) @@ -45,6 +49,12 @@ class Command(ScrapyCommand): opts.spargs = arglist_to_dict(opts.spargs) except ValueError: raise UsageError("Invalid -a value, use -a NAME=VALUE", print_help=False) + if opts.output: + if opts.output == '-': + self.settings.overrides['FEED_URI'] = 'stdout:' + else: + self.settings.overrides['FEED_URI'] = opts.output + self.settings.overrides['FEED_FORMAT'] = opts.output_format def run(self, args, opts): if len(args) != 1: