get_data.py 950 B

123456789101112131415161718192021222324252627282930
  1. """
  2. 从文件数据库中获取文本数据
  3. """
  4. import json
  5. import os
  6. import re
  7. import requests
  8. import pymongo
  9. class Mongo(object):
  10. def __init__(self):
  11. self.conn = pymongo.MongoClient("mongodb://192.168.1.140:27017/") # 创建数据库连接
  12. # self.conn = pymongo.MongoClient('mongodb://localhost:27017/') # 创建数据库连接
  13. self.db_name = 'zy' # 数据库名称
  14. self.table_name = 'spider.files' # 表名称
  15. self.spider_db = self.conn[self.db_name] # 新建数据库名,
  16. self.meta_db = self.spider_db[self.table_name] # meta data about files 文件题库
  17. def get_data_info(self, query):
  18. for data in self.meta_db.find(query):
  19. return data
  20. if __name__ == "__main__":
  21. from bson.objectid import ObjectId # 只需安装pymongo即可
  22. mongo = Mongo()
  23. aa = mongo.get_data_info({"_id" : ObjectId("5fc64c094994183dda7e7575")})
  24. print(aa["item_ocr"])