工具
精华
|
战斗力 鹅
|
回帖 0
注册时间 2017-11-17
|
楼主 |
发表于 2018-12-4 14:15
|
显示全部楼层
看到方框没有?
- import codecs #载入模块
- import re #载入模块
- import os #载入模块
- for htmlfile1 in (os.listdir("AQ")): #统计目录文件
- htmlfile='AQ/{htmlfile2}'.format(htmlfile2=htmlfile1) #获取文件名变量
- htmlfileok='AQ2/{htmlfile2}'.format(htmlfile2=htmlfile1) #处理后文件名变量
- with codecs.open(htmlfile, 'r+', 'utf-8') as f: #打开文件
- htmlsource = f.read() #提取文件
-
- chazhaojerry0 = r'class="jerry0"' #查找条件判断内容0
- chazhaojieguo0 = len(re.findall(chazhaojerry0,htmlsource)) #查找结果0
- chazhaojerry1 = r'class="jerry1"' #查找条件判断内容1
- chazhaojieguo1 = len(re.findall(chazhaojerry1,htmlsource)) #查找结果1
- if chazhaojieguo0 > 0:
- #print('找到目标jerry0')
- f = codecs.open(htmlfile,'r+','utf-8') #打开源文件
- f2 = codecs.open(htmlfileok,'w','utf-8') #新建目标文件
- for s1 in f.readlines(): #循环打开行并赋值给S4
- questions1 = ['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''] #编码方式4
- answers1 = ['I','J','0','x','P','X','Y','U','M','N','Z','7','A','B','C','D','O','9','G','E','F','R','K','H','2','L','Q','8','3','4','S','W','V','6','1','T','5','e','f','g','h','i','j','k','n','l','m','Z','y','V','p','o','d','q','t','c','W','a','r','s','u','b'] #编码方式4对应字符4
- for q1, a1 in zip(questions1, answers1): #循环所有编码
- s1=(s1.replace(q1,a1)) #替换编码为对应字符
-
- f2.write(s1) #写入替换结果
- f.close() #关闭源文件
- f2.close() #关闭目标文件
-
- elif chazhaojieguo1 > 0:
- #print('找到目标jerry1')
- f = codecs.open(htmlfile,'r+','utf-8') #打开源文件
- f2 = codecs.open(htmlfileok,'w','utf-8') #新建目标文件
- for s2 in f.readlines(): #循环打开行并赋值给S4
- questions2 = ['','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',''] #编码方式4
- answers2 = ['1','0','Q','Y','8','I','9','Z','G','n','l','S','O','c','N','t','E','5','T','k','y','o','2','j','z','B','m','h','M','L','w','i','q','K','R','F','b','U','7','D','f','g','p','d','P','W','v','C','3','H','A','x','r','6','u','V','X','a','J','4','s','e'] #编码方式4对应字符4
- for q2, a2 in zip(questions2, answers2): #循环所有编码
- s2=(s2.replace(q2,a2)) #替换编码为对应字符
-
- f2.write(s2) #写入替换结果
- f.close() #关闭源文件
- f2.close() #关闭目标文件
-
- else:
- print('没有找到目标')
复制代码
|
|