1. 服务开启
在cmd-命令行窗口中输入:
net start MongoDB
2. 可视化工具Robomongo
右键 ADD,保存默认设置——save——connect连接数据库
3. python插入
创建数据库
import pymongo
client = pymongo.MongoClient('localhost',27017) #连接数据库
mydb=client['zhihu_100000'] #创建名为'zhihu_100000'的数据库
psy=mydb['psy'] #创建数据集合
cont=mydb['cont']
topic=mydb['topic']
插入
url_root=['https://www.zhihu.com/topic/19642170/top-answers',#心理现象
'https://www.zhihu.com/topic/19562796/top-answers',#人格
'https://www.zhihu.com/topic/19556937/top-answers',#情绪 ]
topic.insert_one({'key':'心理现象','url':url_root[0]})
数据获取:将数据转为DataFrame,然后通过列名得到所需数据
topics=DataFrame(list(topic.find()))['key']