蜘蛛爬虫中的读取设置 [英] Reading settings in spider scrapy

查看:25
本文介绍了蜘蛛爬虫中的读取设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wrote a small scrapy spider. Following is my code

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.我怎样才能做到这一点?

My question is, I want to read the name,allowed_domains and start_urls using setting. How can i do this?

我尝试导入

 from scrapy.settings import Settings

也试过这个

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

但我没有/错误.帮我阅读蜘蛛中的设置?

but I got none/error. Help me to read settings in my spider?

推荐答案

from scrapy.utils.project import get_project_settings

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

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

Using this code we can read data from settings file...

这篇关于蜘蛛爬虫中的读取设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆