我正在尝试使用四个蜘蛛部署一个爬虫.其中一个蜘蛛使用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给出了一个很好的答案:
原文链接:https://www.f2er.com/python/439588.html我的init函数是:
def __init__(self,domain_name):
为了在一个鸡蛋中使用scrapyd,它应该是:
def __init__(self,domain_name,**kwargs):
考虑将domain_name作为强制参数传递