运行scrapy蜘蛛时出现Scrapyd init错误

时间:2013-07-31 16:08:30

标签: python python-2.7 scrapy scrapyd

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

  

TypeError: init ()得到了一个意外的关键字参数'_job'

从我读过的内容可以看出蜘蛛中的init函数存在问题,但我似乎无法解决问题。我不需要init函数,如果我完全删除它,我仍然会收到错误!

My Spider看起来像这样

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

我可以在蜘蛛中使用init函数,但是我得到完全相同的错误。

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

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

1 个答案:

答案 0 :(得分:4)

alecx给出了一个好的答案:

我的初始化功能是:

def __init__(self, domain_name):

为了在鸡蛋中使用scrapyd,它应该是:

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

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