5

我正在尝试部署一个带有四个蜘蛛的爬虫。其中一个蜘蛛使用 XMLFeedSpider 并在 shell 和 scrapyd 中运行良好,但其他蜘蛛使用 BaseSpider 并且在 scrapyd 中运行时都会出现此错误,但在 shell 中运行良好

TypeError: init () got an unexpected keyword argument '_job'

从我读到的内容来看,这表明我的蜘蛛中的 init 函数存在问题,但我似乎无法解决这个问题。我不需要初始化函数,如果我完全删除它,我仍然会收到错误!

我的蜘蛛看起来像这样

from scrapy import log
from scrapy.spider import BaseSpider
from scrapy.selector import XmlXPathSelector
from betfeeds_master.items import Odds
# Parameters
MYGLOBAL = 39
class homeSpider(BaseSpider): 
    name = "home" 
    #con = None

    allowed_domains = ["www.myhome.com"]
    start_urls = [
        "http://www.myhome.com/oddxml.aspx?lang=en&subscriber=mysubscriber",
    ]
    def parse(self, response):

        items = []

        traceCompetition = ""

        xxs = XmlXPathSelector(response)
        oddsobjects = xxs.select("//OO[OddsType='3W' and Sport='Football']")
        for oddsobject in oddsobjects:
            item = Odds()
            item['competition'] = ''.join(oddsobject.select('Tournament/text()').extract())
            if traceCompetition != item['competition']:
                log.msg('Processing %s' % (item['competition']))                #print item['competition']
                traceCompetition = item['competition']
            item['matchDate'] = ''.join(oddsobject.select('Date/text()').extract())
            item['homeTeam'] = ''.join(oddsobject.select('OddsData/HomeTeam/text()').extract())
            item['awayTeam'] = ''.join(oddsobject.select('OddsData/AwayTeam/text()').extract())
            item['lastUpdated'] = ''
            item['bookie'] = MYGLOBAL
            item['home'] = ''.join(oddsobject.select('OddsData/HomeOdds/text()').extract())
            item['draw'] = ''.join(oddsobject.select('OddsData/DrawOdds/text()').extract())
            item['away'] = ''.join(oddsobject.select('OddsData/AwayOdds/text()').extract())

            items.append(item)

        return items

我可以在蜘蛛中使用一个初始化函数,但我得到了完全相同的错误。

def __init__(self, *args, **kwargs):
    super(homeSpider, self).__init__(*args, **kwargs)
    pass

为什么会发生这种情况,我该如何解决?

4

1 回答 1

4

alecx 给出了很好的答案:

我的初始化函数是:

def __init__(self, domain_name):

为了在scrapyd的鸡蛋中工作,它应该是:

def __init__(self, domain_name, **kwargs):

考虑到您将 domain_name 作为强制参数传递

于 2014-10-08T13:08:23.953 回答