python - 蜘蛛scrapy中的读取设置

标签 python scrapy

我写了一个小的 scrapy 蜘蛛。以下是我的代码

class ElectronicsSpider(scrapy.Spider):
    name = "electronics"
    allowed_domains = ["www.olx.com"]
    start_urls = ['http://www.olx.com/']

    def parse(self, response):
        pass

我的问题是,我想使用设置读取名称、allowed_domains 和 start_urls。我怎样才能做到这一点?

我试过导入

 from scrapy.settings import Settings

也试过了

 def __init__(self,crawler):
        self.settings = crawler.settings

但我没有/错误。帮助我读取我的蜘蛛中的设置?

最佳答案

from scrapy.utils.project import get_project_settings

settings=get_project_settings()
print settings.get('NAME')

使用这段代码我们可以从设置文件中读取数据...

关于python - 蜘蛛scrapy中的读取设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45230147/

相关文章:

python - httplib2 使用代理给出内部服务器错误 500

python - 在 xpath 中使用列表变量

python - Scrapy找不到蜘蛛

python - 将 >2GB 数据传递给 tf.estimator

python - systemd中pyenv下的jupyter笔记本仅提供系统python

mysql - Pipeline 不写入 MySQL,但也没有给出错误

xpath - Scrapy bot 和 shell 使用相同的 xpath 查询返回不同的结果。为什么?

python - Scrapy 荣誉 rel=nofollow

python - 在 Python 中使用循环删除列表项

python - 点积稀疏矩阵