치료 파이프 라인에 문제가 있습니다. EnricherPipeline이 절대로 시작되지 않습니다. 나는 process_item의 첫 번째 줄에 디버거를 넣었고 제어권을 얻지 못했다. JsonPipeline 시작 않지만, 수신하는 첫 번째 인수는 유형 generator object process_item
이다 아닌 MatchItem 인스턴스가 내가 EnricherPipeline을 사용하지 않는 경우 예상대로 JsonPipeline 작동 (수신한다.치료 파이프 라인이 시작되지 않음
class MatchSpider(CrawlSpider):
def parse(self, response):
browser = Browser(browser='Chrome')
browser.get(response.url)
browser.find_element_by_xpath('//a[contains(text(), "{l}") and @title="{c}"]'.format(l=self.league, c=self.country)).click()
browser.find_element_by_xpath('//select[@id="seasons"]/option[text()="{s}"]'.format(s=self.season.replace('-', '/'))).click()
browser.find_element_by_xpath('//a[contains(text(), "Fixture")]').click()
page_matches = browser.find_elements_by_xpath('//*[contains(@class, "result-1 rc")]')
matches.extend([m.get_attribute('href') for m in page_matches]
for m in matches[:1]:
yield Request(m, callback=self.process_match, dont_filter=True)
def process_match(self, response):
match_item = MatchItem()
match_item['url'] = response.url
match_item['project'] = self.settings.get('BOT_NAME')
match_item['spider'] = self.name
match_item['server'] = socket.gethostname()
match_item['date'] = datetime.datetime.now()
return match_item
class EnricherPipeline:
def process_item(self, item, spider):
self.match = defaultdict(dict)
self.match['date'] = item['match']['startTime']
self.match['referee'] = item['match']['refereeName']
self.match['stadium'] = item['match']['venueName']
self.match['exp_mins'] = item['match']['expandedMinutes']
yield self.match
class JsonPipeline:
def process_item(self, item, scraper):
output_dir = 'data/matches/{league}/{season}'.format(league=scraper.league, season=scraper.season)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
file_name = "-".join([str(datetime.strptime(item['date'], '%Y-%m-%dT%H:%M:%S').date()),
item['home']['name'], item['away']['name']]) + '.json'
item_path = os.sep.join((output_dir, file_name))
with open(item_path, 'w') as f:
f.write(json.dumps(item))
ITEM_PIPELINES = {
'scrapers.whoscored.whoscored.pipelines.EnricherPipeline': 300,
'scrapers.whoscored.whoscored.pipelines.JsonPipeline': 800,
}
'scrapers.whoscored.whoscored.pipelines'라는 또 다른 파이프 라인이 있습니다. EnricherPipeline ': 300.이 파이프 라인은 무엇을 반환합니까? – rojeeer
이상하게도, Scrapy는 파이프 라인을 절대 입력하지 않습니다. 첫 번째 줄에는 디버거를 넣습니다. process_item의 그것은 결코 enteres. 그것은 딕트 (dict)를 반환하기로되어 있습니다. – FranGoitia
_ 놀랍게도, 치료사는 결코 그 파이프 라인에 들어 가지 않습니다. _ 게시 한 코드가 단일 파일 (예 :'pipelines.py')이거나 다른 파일입니까? 'ITEM_PIPELINES'는'settings.py' 파일에서 설정 될 것으로 예상됩니다. – starrify