实现多个字符串的批量转换
import re
import os
s = os.sep
root = "G:\daizhuan"
for i in os.listdir(root):
if os.path.isfile(os.path.join(root,i)):
print ("i")
filePath = os.path.join(root,i)
a= open(filePath,'r') #打开所有文件
str = a.read()
str = str.replace("<div", "<view") # 将字符串里前面全部替换为后面
str = str.replace("<p","<view")
str = str.replace("div>", "view>")
str = str.replace("p>", "view>")
print (os.path.join(root,i))
print (str)
b = open(filePath,'w')
b.write(str) #再写入
b.close() #关闭文件
批量转换HTML标签
本文介绍了一个简单的Python脚本,用于批量读取指定目录下的文件,并将文件中的HTML标签(如<div>和<p>)统一替换为<view>标签。这一过程适用于批量处理HTML文件,例如在进行网页适配或格式转换时。
2952

被折叠的 条评论
为什么被折叠?



