本帖最后由 wankoilz 于 2015-10-10 14:24 编辑
时间比较紧,草草的用vbs勉强做了一个。需要把a.html,b.html和脚本放一起执行。
a.html为源文件,b.html为被替换文件,生成新文件为c.html- Set fso = WScript.CreateObject("Scripting.Filesystemobject")
- scriptPath=Replace(WScript.ScriptFullName,WScript.ScriptName,"")
- Set RE=New RegExp
- RE.Global=True
- RE.IgnoreCase=True
- RE.Multiline=True
- RE.Pattern="<ul.*?>(\s*<li(.|\s)*?)</ul>" '(.|\r|\n)或(.|\s)表示任意字符
- Set ado1=CreateObject("adodb.stream")
- '以utf-8格式读取a.html并获取内容
- ado1.Type=2
- ado1.Charset="utf-8"
- ado1.Mode=3
- ado1.Open
- ado1.LoadFromFile(scriptPath&"a.html")
- str=ado1.ReadText()
- Set Matches=RE.Execute(str)
- For Each Match In Matches
- source=Match.Submatches(0)
- Next
- '读取b.html并用获取的内容替换掉相应部分
- ado1.LoadFromFile(scriptPath&"b.html")
- str=ado1.ReadText()
- Set Matches=RE.Execute(str)
- For Each Match In Matches
- result=Replace(str,Match.Submatches(0),source)
- Next
- '用close方法清空数据后再以utf-8格式写入
- ado1.Close
- ado1.Open
- ado1.WriteText(result)
- ado1.SaveToFile scriptPath&"c.html",2
- ado1.Close
复制代码
|