准备学习scrapy,但是按教程运行后显示报错。下面就是scrapy信件的itcast.py基本的框架然后按照教程改了改,
import scrapy
class ItcastSpider(scrapy.Spider):
name = 'itcast'
allowed_domains = ['itcast.cn']
start_urls = ['http://www.itcast.cn/channel/teacher.shtml']
def parse(self, response):
filename = "teacher.html"
open(filename, 'w').write(response.body)
import scrapy
class ItcastItem(scrapy.Item):
name = scrapy.Field()
title = scrapy.Field()
info = scrapy.Field()
C:\Users\SongBeiChen\mySpider>scrapy crawl itcast
c:\users\songbeichen\appdata\local\programs\python\python36\lib\site-packages\OpenSSL\crypto.py:8: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
from cryptography import utils, x509
2022-07-21 22:56:39 [scrapy.utils.log] INFO: Scrapy 2.6.1 started (bot: mySpider)
2022-07-21 22:56:39 [scrapy.utils.log] INFO: Versions: lxml 4.9.1.0, libxml2 2.9.12, cssselect 1.1.0, parsel 1.6.0, w3lib 1.22.0, Twisted 21.2.0, Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)], pyOpenSSL 22.0.0 (OpenSSL 3.0.5 5 Jul 2022), cryptography 37.0.4, Platform Windows-10-10.0.19041-SP0
Traceback (most recent call last):
File "c:\users\songbeichen\appdata\local\programs\python\python36\lib\site-packages\scrapy\spiderloader.py", line 75, in load
return self._spiders[spider_name]
KeyError: 'itcast'
之前运行另一个爬虫在pycharm里直接启动代码也是这个结果,网上搜索没有合适答案
希望能帮忙支支招,说一下为啥报错
你是以scrapy startproject生产的吗?名字应该Spider,你的为什么叫mySpider呀?