mirror of https://github.com/scrapy/scrapy.git
allow to use scrape command without an url
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%40178
This commit is contained in:
parent
77053113cd
commit
e83dcb588e
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue