From f373fc0f7cc8e9926136549078376ad9b76f1a61 Mon Sep 17 00:00:00 2001 From: elpolilla Date: Fri, 5 Dec 2008 17:56:36 +0000 Subject: [PATCH] Modified parse command to make it default to "parse" method if no rules are found --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40474 --- scrapy/trunk/scrapy/command/commands/parse.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/scrapy/trunk/scrapy/command/commands/parse.py b/scrapy/trunk/scrapy/command/commands/parse.py index 424e93bf3..18b4661b6 100644 --- a/scrapy/trunk/scrapy/command/commands/parse.py +++ b/scrapy/trunk/scrapy/command/commands/parse.py @@ -73,20 +73,24 @@ class Command(ScrapyCommand): continue if self.callbacks: - items, links = [], [] for callback in self.callbacks: - r_items, r_links = self.run_callback(spider, response, callback, args, opts) - items.extend(r_items) - links.extend(r_links) + items, links = self.run_callback(spider, response, callback, args, opts) + ret_items.extend(items) + ret_links.extend(links) + continue elif opts.rules: - for rule in getattr(spider, 'rules', ()): - if rule.link_extractor.matches(response.url): - items, links = self.run_callback(spider, response, rule.callback, args, opts) - break + rules = getattr(spider, 'rules') + if rules: + items, links = [], [] + for rule in rules: + if rule.callback and rule.link_extractor.matches(response.url): + items, links = self.run_callback(spider, response, rule.callback, args, opts) + break else: - log.msg('No rules found for spider "%s", please specify a parsing callback' % spider.domain_name) - continue + log.msg('No rules found for spider "%s", calling default method "parse"' % spider.domain_name) + items, links = self.run_callback(spider, response, 'parse', args, opts) + else: items, links = self.run_callback(spider, response, 'parse', args, opts)