1、引入from scrapy.utils.project import get_project_settings
2、利用get_project_settings()读取settings.py中的属性
在middlewares.py文件中读取setting属性
from scrapy.utils.project import get_project_settings
class YourSpider(BaseSpider):
def parse(self, response):
settings = get_project_settings()
print “Your USER_AGENT is:\n%s” % (settings.get(‘USER_AGENT’))
#USER_AGENT 在settings.py中定义好的