【发布时间】:2014-10-14 11:20:59
【问题描述】:
我正在尝试编写我的第一个scrapy spider,我一直在关注http://doc.scrapy.org/en/latest/intro/tutorial.html 上的教程但是我收到一个错误“KeyError: 'Spider not found:”
我想我正在从正确的目录(带有 scrapy.cfg 文件的目录)运行命令
(proscraper)#( 10/14/14@ 2:06pm )( tim@localhost ):~/Workspace/Development/hacks/prosum-scraper/scrapy
tree
.
├── scrapy
│ ├── __init__.py
│ ├── items.py
│ ├── pipelines.py
│ ├── settings.py
│ └── spiders
│ ├── __init__.py
│ └── juno_spider.py
└── scrapy.cfg
2 directories, 7 files
(proscraper)#( 10/14/14@ 2:13pm )( tim@localhost ):~/Workspace/Development/hacks/prosum-scraper/scrapy
ls
scrapy scrapy.cfg
这是我遇到的错误
(proscraper)#( 10/14/14@ 2:13pm )( tim@localhost ):~/Workspace/Development/hacks/prosum-scraper/scrapy
scrapy crawl juno
/home/tim/.virtualenvs/proscraper/lib/python2.7/site-packages/twisted/internet/_sslverify.py:184: UserWarning: You do not have the service_identity module installed. Please install it from <https://pypi.python.org/pypi/service_identity>. Without the service_identity module and a recent enough pyOpenSSL tosupport it, Twisted can perform only rudimentary TLS client hostnameverification. Many valid certificate/hostname mappings may be rejected.
verifyHostname, VerificationError = _selectVerifyImplementation()
Traceback (most recent call last):
File "/home/tim/.virtualenvs/proscraper/bin/scrapy", line 9, in <module>
load_entry_point('Scrapy==0.24.4', 'console_scripts', 'scrapy')()
File "/home/tim/.virtualenvs/proscraper/lib/python2.7/site-packages/scrapy/cmdline.py", line 143, in execute
_run_print_help(parser, _run_command, cmd, args, opts)
File "/home/tim/.virtualenvs/proscraper/lib/python2.7/site-packages/scrapy/cmdline.py", line 89, in _run_print_help
func(*a, **kw)
File "/home/tim/.virtualenvs/proscraper/lib/python2.7/site-packages/scrapy/cmdline.py", line 150, in _run_command
cmd.run(args, opts)
File "/home/tim/.virtualenvs/proscraper/lib/python2.7/site-packages/scrapy/commands/crawl.py", line 58, in run
spider = crawler.spiders.create(spname, **opts.spargs)
File "/home/tim/.virtualenvs/proscraper/lib/python2.7/site-packages/scrapy/spidermanager.py", line 44, in create
raise KeyError("Spider not found: %s" % spider_name)
KeyError: 'Spider not found: juno'
这是我的虚拟环境:
(proscraper)#( 10/14/14@ 2:13pm )( tim@localhost ):~/Workspace/Development/hacks/prosum-scraper/scrapy
pip freeze
Scrapy==0.24.4
Twisted==14.0.2
cffi==0.8.6
cryptography==0.6
cssselect==0.9.1
ipdb==0.8
ipython==2.3.0
lxml==3.4.0
pyOpenSSL==0.14
pycparser==2.10
queuelib==1.2.2
six==1.8.0
w3lib==1.10.0
wsgiref==0.1.2
zope.interface==4.1.1
这是我的蜘蛛的代码,其中填写了 name 属性:
(proscraper)#( 10/14/14@ 2:14pm )( tim@localhost ):~/Workspace/Development/hacks/prosum-scraper/scrapy
cat scrapy/spiders/juno_spider.py
import scrapy
class JunoSpider(scrapy.Spider):
name = "juno"
allowed_domains = ["http://www.juno.co.uk/"]
start_urls = [
"http://www.juno.co.uk/dj-equipment/"
]
def parse(self, response):
filename = response.url.split("/")[-2]
with open(filename, 'wb') as f:
f.write(response.body)
【问题讨论】:
-
/home/tim/.virtualenvs/proscraper/lib/python2.7/site-packages/twisted/internet/_sslverify.py:184:用户警告:您没有安装 service_identity 模块。请从 pypi.python.org/pypi/service_identity> 安装它。如果没有 service_identity 模块和足够新的 pyOpenSSL 来支持它,Twisted 只能执行基本的 TLS 客户端主机名验证。许多有效的证书/主机名映射可能会被拒绝。你需要安装那个模块
-
我认为这不会影响命令的查找
-
好的,我安装了它
pip install service_identity我仍然得到同样的错误 -
尝试像这样重新创建您的项目:
scrapy startproject junoprojectscrapy genspider juno juno.co.uk在您发布时编辑您的蜘蛛,然后再次运行。我可以很好地运行这个 -
我不会使用
items.py、settings.py等将文件夹称为“scrapy”。选择另一个名字