【问题标题】:Scrapyd init error when running scrapy spider运行scrapy spider时Scrapyd初始化错误
【发布时间】:2013-08-01 06:41:55
【问题描述】:

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

TypeError: init() 得到了一个意外的关键字参数“_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

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

【问题讨论】:

  • 你在其他蜘蛛中定义了__init__方法吗?问题可能是您不接受**kwargs 那里..
  • XMLFeedSpider 并没有从BaseSpider 覆盖太多,所以我不明白为什么这些蜘蛛会触发这个错误。 (github.com/scrapy/scrapy/blob/master/scrapy/contrib/spiders/…)。你能发布更完整的堆栈跟踪吗?

标签: python python-2.7 scrapy scrapyd


【解决方案1】:

alecx 给出了很好的答案:

我的初始化函数是:

def __init__(self, domain_name):

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

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

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

【讨论】:

    猜你喜欢
    • 2015-10-13
    • 2015-07-09
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 2019-12-10
    • 2020-09-26
    相关资源
    最近更新 更多