繁体   English   中英

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

[英]Scrapyd init error when running scrapy spider

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

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

从我所看到的,这指向我的蜘蛛中的init函数的问题,但我似乎无法解决问题。 我不需要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

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

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

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

alecx给出了一个很好的答案:

我的init函数是:

def __init__(self, domain_name):

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM