您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python 中使用 MongoDB 存储爬虫数据

2024/5/24 19:08:48发布32次查看
现在在做一个简单的搜索引擎,使用今日头条的新闻数据作为数据源。这些数据都是非结构性的,比较适合用 mongodb 来进行存储。
以下为简单使用的示例。
#!/usr/bin/python # -*- coding:utf-8 -*- import pymongo class documentmanager(object): def __init__(self): pass def connect_mongo(self): client = pymongo.connection(127.0.0.1,27017) db = client.data_db collection = db.data_collection mydict = {name:lucy, sex:female,job:nurse} collection.insert(mydict) for i in collection.find({name:lucy}): print i if __name__ == '__main__': manager = documentmanager() manager.connect_mongo()
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product