import codecs
import webbrowser
import sys
charset = "utf-8" #文件编码
#读取text里的<include>标签及src属性中的文件,替换原标签
def replaceInclude (filename,text):
try:
posA = text.find("<include")
while posA!= -1:
posC = text.find(">",posA)
tag = text[posA:posC+1]
posA = text.find("src=",posA)
posA += 5
posB = text.find("\"",posA)
file = text[posA:posB]#获取src中的文件名
print ("正在处理:",file)
tmpFile = codecs.open(file,"r",charset)
tmpText = tmpFile.read()
tmpText = replaceInclude(file,tmpText)#递归处理文件嵌套后的include标签
text = text.replace(tag,tmpText)
tmpFile.close()
posA = text.find("<include")
return text;
except Exception as e:
print ("错误:文件",filename,"中的",file,"处理失败!错误信息:\n",e)
sys.exit(1)
readFile = codecs.open("index.html","r",charset)
writeFile = codecs.open("newhtml.html","w",charset)
try:
text = readFile.read()
text = replaceInclude("index.html",text)
writeFile.write(text)
webbrowser.open("newhtml.html")
finally:
readFile.close()
writeFile.close()</pre>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有