我在用Scrapy写爬虫。我已经造了一个爬虫,它工作得很好。
现在我想创建自己的模块,但我总是收到以下错误:
文件"D:\Projects\bitbucket\terranoha\crawl1\crawl1\spiders\samplecrawler.py",第4行,在导入模块中 ModuleNotFoundError:没有名为“模块测试”的模块
守则是:
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
import moduletest
class SamplecrawlerSpider(CrawlSpider):
# [...]我在跑步:scrapy crawl --nolog samplecrawler。我在Windows 10上。
我的项目结构是:

发布于 2018-12-20 15:05:16
你可以做几件事:
First
from crawl1.spiders.moduletest import mythings如@elRuLL所示
第二
from .moduletest import mythings这通常是一个糟糕而脆弱的解决方案,但是可能的。
第三代
你可以把它打包成包,然后做。
init__.py:
from spiders.moduletest import *
__all__ = [<Put your classes, methods, etc here>]samplecrawler.py
import moduletest发布于 2018-12-20 14:59:14
您需要包含完整的模块路径:
from crawl1.spiders.moduletest import mythings发布于 2018-12-20 15:02:46
您必须将文件夹的名称包含为模块名。
import crawl1.spiders.moduletesthttps://stackoverflow.com/questions/53871052
复制相似问题