私は治療パイプラインに問題があります。 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.pipeline」というパイプラインがあります。 EnricherPipeline ':300.このパイプラインは何を返すのですか? – rojeeer
奇妙なことに、Scrapyはパイプラインに入ることはありません。私は最初の行にデバッガを置きますprocess_itemのそれは決してenteres。それはdictを返すことになっています。 – FranGoitia
_もちろん、Scrapyはそのパイプラインに入ることはありません。_投稿したコードは単一のファイル(例: 'pipelines.py')または別のファイルからですか? 'ITEM_PIPELINES'は' settings.py'ファイルに設定されています。 – starrify