scrapy - Scrapy: Can't define bot name anymore in scrapy 2.1.0
问题描述
I have a scrapy 2.1 project running where I have under the root directory two folders. My intention is to have 2 projects with seperate bots and settings in addition to a global setting.
Now I tried to define project names, so I used the export command. Unfortunatelly this somehow changed the bot name to "scrapybot" and it is not possible to rename it again:
merlin@192-143-0-9 spider1 % export SCRAPY_PROJECT=bid
merlin@192-143-0-9 spider1 % scrapy settings --get BOT_NAME
scrapybot
The project is within a git repo and doing a git status, it does show no changes at all. The spider list is empty now due to the renamed project.
This looks like a bug to me, so my main question is:
- How can I rename my bot back to it`s original name "bid" where all spiders are located?
Once I have it back running, the second question which led me to the current problem is:
- How can I specify two different projects under one root directory with their own spiders and settings?
解决方案
- 很正常
git status
,没啥区别。你只是设置一个环境变量。scrapy settings
将从 settings.py 文件中读取值,因此根据您所在的项目文件夹,它会给您“bid”或“scrapybot” - 以下结构允许您在 1 个根目录下拥有多个 scrapy 项目,每个项目都有自己的设置和蜘蛛:
root/
scrapy.cfg
bid/
__init__.py
items.py
middlewares.py
pipelines.py
settings.py
spiders/
bidspider.py
scrapybot/
__init__.py
items.py
middlewares.py
pipelines.py
settings.py
spiders/
scrapybotspider.py
推荐阅读
- python - 将python中定义的变量解析为文本文件
- java - 如何在主类中创建类 x 的对象时向类 x 中的 ArrayList 添加值
- php - 没有库的 PHP 中的 GraphQL 查询
- r - 一旦CSV在R中的间隔更新,我如何刷新CSV中的值?
- r - 在 R 中使用自动分配将图例添加到散点图
- javascript - 将 :id 添加到受保护的组件路径会导致无限循环?
- fluentvalidation - 如何在 OpenAPI json 中包含 RegexOptions 以指示小写
- swift - Swift PDFView 和以“/pdf”而不是“.pdf”结尾的 URL
- dependency-injection - NetCore - 解决内部依赖
- c# - 如何使用 ASP.NET Core 2.1 中的网站界面为用户分配角色