我写了一个小的 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/