Unknown command: crawl

在执行 scrapy 时,报如下错误:

Unknown command: crawl
 
Use "scrapy" to see available commands

解决方法:

1、创建 scrapy 项目,并进入项目

scrapy startproject tutorial
cd tutorial

2、在项目根目录下的 tutorial/spiders/ 下新建爬虫文件 quotes_spider.py

vi quotes_spider.py
 
import scrapy
 
 
class QuotesSpider(scrapy.Spider):
    name = "quotes"
 
    def start_requests(self):
        urls = [
            'http://quotes.toscrape.com/page/1/',
            'http://quotes.toscrape.com/page/2/',
        ]
        for url in urls:
            yield scrapy.Request(url=url, callback=self.parse)
 
    def parse(self, response):
        page = response.url.split("/")[-2]
        filename = 'quotes-%s.html' % page
        with open(filename, 'wb') as f:
            f.write(response.body)
        self.log('Saved file %s' % filename)

3、返回到项目根目录,执行如下代码,能够成功执行爬虫程序

scrapy crawl quotes

 

你可能感兴趣的:(Unknown command: crawl)