''' Created on 2019年12月18日 @author: User ''' import pymongo import re import pandas as pd def getDatafromMongo(): client = pymongo.MongoClient("mongodb://bxkc_read:BidiReadOnly2017@47.98.60.3:17017/bxkc") db = client["bxkc"] collection_enterprise = db['zhaobiao_extraction'] cursor = collection_enterprise.find({"page_time":{"$gte":'2019-03-01'}}).limit(5000) list_docid = [] list_projectName = [] list_title = [] print("done") _index = 0 for row in cursor: print(row) _index += 1 list_docid.append(row["docId"]) list_projectName.append(row["project_name"]) list_title.append(row["document_title"]) #print(_index,row["project_name"]) print("done") df = pd.DataFrame({"list_docid":list_docid,"list_projectName":list_projectName,"list_title":list_title}) df.to_excel("repairName.xls",columns=["list_docid","list_projectName","list_title"]) if __name__=="__main__": getDatafromMongo()