本文介绍了scrapy 如何导入设置以覆盖它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

class Test(Spider):
    self.settings.overrides['JOBDIR']= "seen"

我得到了:

  File "C:\Python27\lib\site-packages\scrapy\spider.py", line 46, in settings
    return self.crawler.settings
  File "C:\Python27\lib\site-packages\scrapy\spider.py", line 41, in crawler
    assert hasattr(self, '_crawler'), "Spider not bounded to any crawler"
AssertionError: Spider not bounded to any crawler

我正在扩展 Spider 并且我没有使用 Crawler 因为我没有链接或要遵循的规则

I am extending Spider and I am not using Crawler because I don't have links nor rules to follow

我猜我的问题是因为我没有很好地导入设置,我需要你的帮助

I am guessing that my problem is because I didn't import the settings well and I need your help please

推荐答案

为了更改蜘蛛中的设置,您可以:

In order to change the settings in the spider you can:

class TestSpider(Spider):

    def set_crawler(self, crawler):
        super(TestSpider, self).set_crawler(crawler)
        crawler.settings.set('JOBDIR','seen')

    # rest of spider code

这篇关于scrapy 如何导入设置以覆盖它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 11:36