-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipelines.py
33 lines (26 loc) · 957 Bytes
/
pipelines.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from pymongo import *
class JdBookMongoPipeline(object):
def open_spider(self,spider):
if spider.name == 'jd':
client = MongoClient(host='127.0.0.1',port=27017)
db = client.jd
self.items = db.items
def process_item(self, item, spider):
if spider.name == 'jd':
self.items.insert(dict(item))
return item
class AmazonBookMongoPipeline(object):
def open_spider(self,spider):
if spider.name == 'amazon':
client = MongoClient(host='127.0.0.1',port=27017)
db = client.amazon
self.items = db.items
def process_item(self, item, spider):
if spider.name == 'amazon':
self.items.insert(dict(item))
return item