1、在scrapy的pipeline中,获取settings参数,可使用如下方式:
def open_spider(self, spider):
settings = spider.settings
web_dir_dict = settings.get('WEB_DIR_DICT', {})
也可以采用如下方式:
from scrapy.utils.project import get_project_settings
###中间代码略
def open_spider(self, spider):
settings = get_project_settings()
web_dir_dict = settings.get('WEB_DIR_DICT', {})
2、如果settings中的参数是小写的,比如上面代码中的WEB_DIR_DICT如果写成web_dir_dict,则会获取不到。