pipelines.py 708 B

12345678910111213141516171819202122232425
  1. # -*- coding: utf-8 -*-
  2. # Define your item pipelines here
  3. #
  4. # Don't forget to add your pipeline to the ITEM_PIPELINES setting
  5. # See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
  6. import pymongo
  7. from scrapy.conf import settings
  8. class HouseSpiderPipeline(object):
  9. def process_item(self, item, spider):
  10. return item
  11. class LianjiaVillageSavePipeline(object):
  12. def __init__(self):
  13. pass
  14. def process_item(self, item, spider):
  15. if spider.name == 'lianjia':
  16. client = pymongo.MongoClient(host=settings['MONGO_HOST'], port=settings['MONGO_PORT'])
  17. db = client['house']
  18. coll = db[item.collection]
  19. coll.insert(dict(item))