1 Star 0 Fork 0

小聚团队/lianjia_scrapy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pipelines.py 937 Bytes
一键复制 编辑 原始数据 按行查看 历史
wutairui 提交于 2017-03-17 09:56 . first version
# -*- coding: utf-8 -*-
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
import pymongo
from scrapy.conf import settings
from .items import CqFangItem
import traceback
class CqfangPipeline(object):
def __init__(self):
host = settings['MONGODB_HOST']
port = settings['MONGODB_PORT']
db_name = settings['MONGODB_DBNAME']
client = pymongo.MongoClient(host=host, port=port)
tdb = client[db_name]
self.post = tdb[settings['MONGODB_DOCNAME']]
def process_item(self, item, spider):
if isinstance(item,CqFangItem):
try:
info = dict(item)
print(info)
if self.post.insert(info):
print('bingo')
except Exception:
traceback.print_exc()
return item
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaojuorg/lianjia_scrapy.git
git@gitee.com:xiaojuorg/lianjia_scrapy.git
xiaojuorg
lianjia_scrapy
lianjia_scrapy
master

搜索帮助