Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

allow to use scrape command without an url

olveyrae83dcb588e40
diff --git a/scrapy/trunk/scrapy/command/commands/scrape.py b/scrapy/trunk/scrapy/command/commands/scrape.py
index 4288960c9..5809f6851 100644
--- a/scrapy/trunk/scrapy/command/commands/scrape.py
+++ b/scrapy/trunk/scrapy/command/commands/scrape.py
@@ -20,11 +20,12 @@ def load_url(url, response):
itemcls = load_class(settings['DEFAULT_ITEM_CLASS'])
item = itemcls()
vars['item'] = item
- vars['url'] = url
- vars['response'] = response
vars['xxs'] = XmlXPathSelector(response)
vars['hxs'] = HtmlXPathSelector(response)
- vars['spider'] = spiders.fromurl(url)
+ if url:
+ vars['url'] = url
+ vars['response'] = response
+ vars['spider'] = spiders.fromurl(url)
vars['get'] = get_url
return vars
@@ -40,7 +41,7 @@ def print_vars(vars):
class Command(ScrapyCommand):
def syntax(self):
- return "<url>"
+ return "[url]"
def short_desc(self):
return "Interactive scraping console"
@@ -53,23 +54,26 @@ class Command(ScrapyCommand):
pass
def run(self, args, opts):
- if not args:
- return False
- url = args[0]
+
+ url = None
+ if args:
+ url = args[0]
print "Scrapy %s - Interactive scraping console\n" % scrapy.__version__
print "Enabling Scrapy extensions...",
extensions.load()
print "done"
- print "Downloading URL... ",
- responses = fetch([url])
- print "done"
- if not responses:
- if not opts.loglevel:
- print 'Nothing downloaded, run with -o DEBUG to see why it failed'
- return
- response = responses[0]
+ response = None
+ if url:
+ print "Downloading URL... ",
+ responses = fetch([url])
+ print "done"
+ if not responses:
+ if not opts.loglevel:
+ print 'Nothing downloaded, run with -o DEBUG to see why it failed'
+ return
+ response = responses[0]
vars = load_url(url, response)
self.update_vars(vars)