LoginSignup
3
4

More than 5 years have passed since last update.

ScrapyでItem Pipelineにsettingsを渡す方法

Posted at

from_settingsだけ定義すると、Item Pipelineごして有効にならない。
下記のように、initでちゃんと定義し直す必要がある。

class MySQLStorePipeline(object):

    @classmethod
    def from_settings(cls, settings):
        return cls(settings.get('DB_SETTING'))

    def __init__(self, db_settings):
        db.init_session(db_settings)

    def process_item(self, item, spider):
        shop = Shop(
            brand_id=1,
            name=item['name'],
            address=item['address'])
        db.db_session.add(shop)
        db.db_session.commit()
        return item
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4