2013-07-31 27 views
5

Tôi đang cố triển khai trình thu thập thông tin với bốn trình thu thập thông tin. Một trong những con nhện sử dụng XMLFeedSpider và chạy tốt từ vỏ và scrapyd, nhưng những người khác sử dụng BaseSpider và tất cả cho lỗi này khi chạy trong scrapyd, nhưng chạy tốt từ vỏLỗi init của Scrapyd khi chạy spider lùn

TypeError: init() got an unexpected keyword argument '_job'

Từ những gì tôi đã đọc điểm cho một vấn đề với chức năng init trong nhện của tôi, nhưng tôi dường như không thể giải quyết vấn đề. Tôi không cần chức năng init và nếu tôi xóa hoàn toàn, tôi vẫn gặp lỗi!

My Spider trông như thế này

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 

tôi có thể đưa việc sử dụng một hàm init vào con nhện, nhưng tôi nhận được chính xác những lỗi tương tự.

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

Tại sao điều này xảy ra và làm cách nào để giải quyết?

+2

Bạn đã xác định phương pháp '__init__' trong các trình thu thập thông tin khác? Vấn đề có thể là bạn không chấp nhận '** kwargs' ở đó .. – alecxe

+0

' XMLFeedSpider' không ghi đè nhiều từ 'BaseSpider' vì vậy tôi không thấy lý do tại sao những trình thu thập thông tin này sẽ kích hoạt lỗi này. (https://github.com/scrapy/scrapy/blob/master/scrapy/contrib/spiders/feed.py). Bạn có thể đăng một dấu vết ngăn xếp hoàn chỉnh hơn không? –

Trả lời

4

Câu trả lời tốt được đưa ra bởi alecx:

hàm init của tôi là:

def __init__(self, domain_name): 

Để làm việc trong một quả trứng cho scrapyd, nó phải là:

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

xem xét bạn vượt qua domain_name làm đối số bắt buộc

+0

thx! Điều này giải quyết được vấn đề của tôi. – Pullie

Các vấn đề liên quan