Scrapy读取设置文件(settings.py)

来自stackflow:
https://stackoverflow.com/questions/14075941/how-to-access-scrapy-settings-from-item-pipeline

读取settings.py

middlewares.py文件中

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中定义好的

你可能感兴趣的:(Python开发日记)