导入settings.py Scrapy

时间:2018-11-05 10:47:16

标签: python scrapy

我有一个testmultiple文件夹,其中包含一个 init 文件,管道,设置和一个core.py文件,我用它们来启动位于子文件夹(spiders)中的多个蜘蛛。我注意到我必须导入设置才能将管道与CrawlerProcess一起使用。这是我的代码-core.py:

import scrapy
from scrapy.crawler import CrawlerProcess
from scrapy.settings import Settings
import settings as my_settings
from spiders.DemoSpider import DemoSpider
from spiders.DemoSpider2 import DemoSpider2


crawler_settings = Settings()
crawler_settings.setmodule(my_settings)
process = CrawlerProcess(settings=crawler_settings)

process.crawl(DemoSpider)
process.crawl(DemoSpider2)
process.start() # the script will block here until the crawling is finished

但是它在第四行失败。有了这个尝试,我有:

ModuleNotFoundError:没有名为“ testmultiple”的模块

当我尝试时:

from testmultiple.settings import settings as my_settings

我也有同样的错误,也有这行:

from testmultiple import settings as my_settings

如何导入settings.py?

0 个答案:

没有答案