随笔分类 - python
摘要:没有找到mongoDB的去重功能,自己写一个,利用分组计数功能,找到count>1的记录,逐一删除重复记录 import pymongo def mongo_dup_remove(db,col,*args): #对指定集合去重 #未考虑数据排序 #支持多个参数 myclient = pymongo.
阅读全文
摘要:用聚合搜索,按照mongoDB官方的文档,使用$not和$regetMatch出现'OperationFailure: unknown top level operator'错误,找不到原因 解决:换一种搜索方式,$not换成$nor,$regetMatch换成re.compile
阅读全文
摘要:服务器运行beautifulsoup时出错,解决办法: 重新安装lxml pip uninstall lxml pip install lxml 还不行就换解析器:bs=BeautifulSoup(res.content,'html.parser')
阅读全文
摘要:载入模块: from datetime import datetime 字符串转datetime格式: time='2021.01.07' datetime.strptime(time,'%Y.%m.%d') time='2021-01-07' datetime.strptime(time,'%Y-
阅读全文
摘要:安装mongoDB:直接下载安装,软件会自动配置,安装后查看服务中有mongoDB即可。 安装pymongo:pip install pymongo 连接本地客户端: myclient = pymongo.MongoClient("mongodb://localhost:27017/") 连接/创建
阅读全文
摘要:载入: import requestsfrom bs4 import BeautifulSoup res = requests.get(url=url,headers=headers)#res=requests.post(url,data,headers=headers) res.raise_for
阅读全文