我創建了一個從CrawlSpider繼承的蜘蛛。Scrapy:無法覆蓋__init__function
我需要使用__init__
功能,但總是收到此錯誤:
代碼:
class mySpider(CrawlSpider):
def __init__(self):
super(mySpider, self).__init__()
.....
這是我得到的錯誤: KeyError異常蜘蛛沒有發現:mySpider。
沒有__init__
功能一切正常
我創建了一個從CrawlSpider繼承的蜘蛛。Scrapy:無法覆蓋__init__function
我需要使用__init__
功能,但總是收到此錯誤:
代碼:
class mySpider(CrawlSpider):
def __init__(self):
super(mySpider, self).__init__()
.....
這是我得到的錯誤: KeyError異常蜘蛛沒有發現:mySpider。
沒有__init__
功能一切正常
你需要把它像這樣:
def __init__(self, *a, **kw):
super(MySpider, self).__init__(*a, **kw)
# your code here
工作例如:
class MySpider(CrawlSpider):
name = "company"
allowed_domains = ["site.com"]
start_urls = ["http://www.site.com"]
def __init__(self, *a, **kw):
super(MySpider, self).__init__(*a, **kw)
dispatcher.connect(self.spider_closed, signals.spider_closed)
這裏的init,使用了蜘蛛註冊scrapy信號,我在這個例子中需要蜘蛛而不是通常在管道中
'super'的語義有時可能會讓人困惑。試試'CrawlSpider .__ init __(self)'。 – 2012-07-21 17:53:05