「PythonとJavaScriptではじめるデータビジュアライゼーション」を読む

6.7 Scrapyパイプライン

P157の最初のコードに# nobel_winners/nobel_winners/setting.pyとあるがpipelines.pyの間違いかな?

#pipelines.py
import scrapy
from scrapy.exceptions import DropItem

class DropNonPersons(object):

    def process_item(self, item, spider):

        if not item['gender']:
            raise DropItem("No gender for %s"%item['name'])
        return item


#settings.py
import os

BOT_NAME = 'nobel_winners'

SPIDER_MODULES = ['nobel_winners.spiders']
NEWSPIDER_MODULE = 'nobel_winners.spiders'


HTTPCACHE_ENABLED = True
ITEM_PIPELINES = {'nobel_winners.pipelines.DropNonPersons':1}

#shllから
$scrapy crawl nwinners_full -o winner_list.json

winner_list.jsonの内訳 受賞者の数1058人、最初の数から9人抜けている
male1001人、female57人、どちらでもない0人
国別の数67国