scrapy pip中间件个人处理

import pymongo
from scrapy.conf import settings
import pymysql



class Mongodb_Pipeline(object):

    def __init__(self):
        self.client = pymongo.MongoClient()
        self.db = self.client[settings.get('MONGODB_NAME')]

    def process_item(self, item, spider):
        if item:
            coll = item['classification1']
            self.db[coll].insert(dict(item))
        return item


    def close_spider(self):
        self.client.close()

不成体系,不要看

 

posted @ 2019-06-27 00:10  花名k  阅读(95)  评论(0编辑  收藏  举报