""" 从文件数据库中获取文本数据 """ import json import os import re import requests import pymongo class Mongo(object): def __init__(self): self.conn = pymongo.MongoClient("mongodb://192.168.1.140:27017/") # 创建数据库连接 # self.conn = pymongo.MongoClient('mongodb://localhost:27017/') # 创建数据库连接 self.db_name = 'zy' # 数据库名称 self.table_name = 'spider.files' # 表名称 self.spider_db = self.conn[self.db_name] # 新建数据库名, self.meta_db = self.spider_db[self.table_name] # meta data about files 文件题库 def get_data_info(self, query): for data in self.meta_db.find(query): return data if __name__ == "__main__": from bson.objectid import ObjectId # 只需安装pymongo即可 mongo = Mongo() aa = mongo.get_data_info({"_id" : ObjectId("5fc64c094994183dda7e7575")}) print(aa["item_ocr"])