YPC*_*ble 5 scrapy scrapy-spider
我有以下目录结构:
my_project/
__init__.py
spiders/
__init__.py
my_spider.py
other_spider.py
pipeines.py
# other files
Run Code Online (Sandbox Code Playgroud)
现在,我可以进入my_project
目录并使用来开始抓取scrapy crawl my_spider
。
我想要实现的是能够以scrapy crawl my_spider
这种更新的结构运行:
my_project/
__init__.py
spiders/
__init__.py
subtopic1/
__init__.py # <-- I get the same error whether this is present or not
my_spider.py
subtopicx/
other_spider.py
pipeines.py
# other files
Run Code Online (Sandbox Code Playgroud)
但是现在我得到这个错误:
KeyError:“未找到蜘蛛:my_spider”
将Scrapy蜘蛛组织到目录中的合适方法是什么?
par*_*ola 13
我知道这已经过期了,但这是在嵌套目录中组织蜘蛛的正确方法。您可以在此处定义的设置中设置模块位置。
例子:
SPIDER_MODULES = ['my_project.spiders', 'my_project.spiders.subtopic1', 'my_project.spiders.subtopicx']
Run Code Online (Sandbox Code Playgroud)
小智 1
您必须从包含scrapy.cfgscrapy crawl my_spider
的目录运行它。您不会收到任何错误。
my_project/
__init__.py
spiders/
__init__.py
my_spider.py
sub_directory
__init__.py
other_spider.py
pipeines.py
scrapy.cfg
Run Code Online (Sandbox Code Playgroud)