w

29.4. __main__ — Top-level script environment — Python 3.6.1 documentation  https://docs.python.org/3/library/__main__.html

D:\pyTOgo\mongoTrans.py

from tool import *
import re '''
危险区,操作不可逆
开始--》
'''
# 批量删除
# deleteMany({'spiderDate': '20180903'}, 'todayUrls')
'''
危险区,操作不可逆
结束《--
'''
'''
以下为
可逆操作
''' # 更新日期字符串冗余- .replace('-', '')
# 更新website字段冗余 .replace('URL:', '')
# cleanData = selectToDic('_id', 'todayUrls', fields={'webSite': 1, 'spiderDate': 1})
# cleanData = selectToDic('_id', 'todayUrls', fields={'Base64parse2times': { '$exists': True}})
'''
collection_name = 'todayUrls'
cleanData = selectToDic('_id', collection_name, fields={'url': 1}, where={'spiderDate': '20180906'})
delIds = []
for i in cleanData:
_id = i
item = cleanData[i]
url = item['url']
pathTag = 'cnhan.com/pinfo/'
# 通过正则删除
if pathTag in url and re.match('^http://www.cnhan.com/pinfo/\d+\.html$',
url) is None:
print(_id, url)
deleteOne({'_id': _id}, collection_name)
''' def improve():
cleanData = selectToDic('_id', 'todayUrls', fields={})
for i in cleanData:
_id = i
item = cleanData[i]
spiderDate = item['spiderDate']
updateOneIdKV(_id, 'spiderDate', spiderDate.replace('-', ''))
print('improve', _id)
if 'webSite' in item:
webSite = item['webSite']
updateOneIdKV(_id, 'webSite', webSite.replace('URL:', '')) def uniqueUrlSpiderDate(collectionMame='todayUrls'):
'''
当日url + spiderDate留其一
:return:
'''
spiderDate_url_set = {}
cleanData = selectToDic('_id', collectionMame, fields={'spiderDate': 1, 'url': 1})
for i in cleanData:
_id = i
item = cleanData[i]
url, spiderDate = item['url'], item['spiderDate']
k = url + spiderDate
if k not in spiderDate_url_set:
spiderDate_url_set[k] = []
spiderDate_url_set[k].append(_id) save_id_l = []
for k in spiderDate_url_set:
save_id_l.append(spiderDate_url_set[k][0])
for i in cleanData:
_id = i
if _id not in save_id_l:
deleteOne({'_id': _id}, collectionMame)
print('uniqueUrlSpiderDate', _id) if __name__ == "__main__":
improve()
uniqueUrlSpiderDate()
uniqueUrlSpiderDate('siteUserPage') D:\pyTOgo\dataAppend.py
from tool import RandomString, selectToDic, updateOne
from mongoTrans import improve, uniqueUrlSpiderDate
from bs4 import BeautifulSoup
import requests, time, json, random cleanDbSwitcher = True if 7 > 9 else False
if cleanDbSwitcher:
improve()
uniqueUrlSpiderDate()
uniqueUrlSpiderDate('siteUserPage') a.py
def fa():
  pass
def fa2():
  pass
fa2()
b.py
import fa from a 没有
if __name__ == "__main__":
则执行fa2()

												

最新文章

  1. 手工配置rsyslog配置文件详解
  2. Qt之C语言有符号数与无符号数运算
  3. .net 制作二维码
  4. SSM项目配置随笔
  5. Junit3与Junit4的区别
  6. hdu1242 优先队列+bfs
  7. 用Nikto探测一个网站所用到的技术
  8. 回调--一个经典例子让你彻彻底底理解java回调机制
  9. js的replace方法
  10. Keil MDK 无法设置断点【worldsing】
  11. JAVA客户端API调用memcached两种方式
  12. 在MacOSX下用管理员权限打开App应用程序
  13. .Net程序员 Solr-5.3之旅 (一)Solr入门
  14. Python学习笔记整理(十)Python的if测试
  15. 只响应ccTouchBegan的问题
  16. 红米手机5 Plus完美刷成开发版获取root权限的教程
  17. python--自己实现的单链表常用功能
  18. laravel框架5.2版本组件包开发
  19. 解决myeclipse2017安装后闪退问题
  20. JS 判断 undefined 类型

热门文章

  1. 客户端通过url向后端传递参数
  2. 剑指offer-二叉树的下一结点-树-python
  3. 1rem,1em,1vh,1px含义
  4. ioncube扩展的安装详细图文教程,适合所有新手
  5. Python 项目转化为so文件
  6. CSS完整
  7. linux 防止误操作 mysql 数据库技巧
  8. 《Java核心技术卷I》——第3章 Java的基本程序设计结构
  9. 023-OpenStack 创建实例类型临时磁盘的讲解
  10. 源讯科技(中国)有限公司(Atos Worldline)