Created
March 21, 2014 10:46
-
-
Save 8maki/9683619 to your computer and use it in GitHub Desktop.
ScrapyでItem Pipelineにsettingsを渡す方法 ref: http://qiita.com/8maki/items/7d994fb730d2a6089e45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment