Python 在不使用settings.py config的情况下使用刮擦管道
我避免使用Scrapy样板生成器,因为我的代码将作为更广泛项目的一部分进行集成 我当前的项目树如下所示:Python 在不使用settings.py config的情况下使用刮擦管道,python,python-3.x,scrapy,Python,Python 3.x,Scrapy,我避免使用Scrapy样板生成器,因为我的代码将作为更广泛项目的一部分进行集成 我当前的项目树如下所示: / test |- items.py |- pipelines.py |- spider.py import pymongo class MongoPipeline(object): collection_name = 'pages' [... rest of the pipeline class ...] Mypipeline.py包含一个如下所示的管道: / tes
/ test
|- items.py
|- pipelines.py
|- spider.py
import pymongo
class MongoPipeline(object):
collection_name = 'pages'
[... rest of the pipeline class ...]
Mypipeline.py
包含一个如下所示的管道:
/ test
|- items.py
|- pipelines.py
|- spider.py
import pymongo
class MongoPipeline(object):
collection_name = 'pages'
[... rest of the pipeline class ...]
如何在spider.py
中使用此类,而不使用settings.py
文件和scrapy.conf
我已尝试导入管道类并在自定义设置中设置项目管道
,但这会引发值错误:加载对象“MongoPipeline”时出错:不是完整路径
:
from pipelines import MongoPipeline
class MySpider(CrawlSpider):
name = 'x'
allowed_domains = ['x']
start_urls = ['x']
custom_settings = {
'ITEM_PIPELINES': {
'MongoPipeline': 100
}
}
def parse(self, response):
[...]
应该是:
custom_settings = {
'ITEM_PIPELINES': {
'YourProjectName.pipelines.MongoPipeline': 100
}
}
谢谢它变成了对我来说只有pipelines.MongoPipeline
(或者对一般情况来说是module.PipelineClass
)。这是在你不使用scrapy项目来运行spider的时候。@Juicy它只是到你的pipelines.py的一条路径