Skip to content
Browse files

Merge pull request #175 from euphoris/master

add options -o and -t to the runspider command
  • Loading branch information...
2 parents a6eacf2 + e94bd81 commit 4ca35dba87ebb73bfb2c702e1437a043bbb037be @pablohoffman pablohoffman committed
Showing with 10 additions and 0 deletions.
  1. +10 −0 scrapy/commands/runspider.py
View
10 scrapy/commands/runspider.py
@@ -38,6 +38,10 @@ def add_options(self, parser):
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 @@ def process_options(self, args, opts):
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:

0 comments on commit 4ca35db

Please sign in to comment.
Something went wrong with that request. Please try again.