加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-16 21:49:11 所属栏目:Python 来源:网络整理
导读:我正在尝试使用四个蜘蛛部署一个爬虫.其中一个蜘蛛使用XMLFeedSpider并从shell和scrapyd运行良好,但其他人使用BaseSpider并且在scrapyd中运行时都会出现此错误,但是从shell运行正常 TypeError: init () got an unexpected keyword argument _job 从我所看到

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

TypeError: init() got an unexpected keyword argument ‘_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作为强制参数传递

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读