方法一
1
2
3'常用函数
4'1、输入url目标网页地址,返回值getHTTPPage是目标网页的html代码
5function getHTTPPage(url)
6dim Http
7set Http=server.createobject("MSXML2.XMLHTTP")
8Http.open "GET",url,false
9Http.send()
10if Http.readystate<>4 then
11exit function
12end if
13getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
14set http=nothing
15if err.number<>0 then err.Clear
16end function
17
18'2、转换乱玛,直接用xmlhttp调用有中文字符的网页得到的将是乱玛,可以通过adodb.stream组件进行转换
19Function BytesToBstr(body,Cset)
20dim objstream
21set objstream = Server.CreateObject("adodb.stream")
22objstream.Type = 1
23objstream.Mode =3
24objstream.Open
25objstream.Write body
26objstream.Position = 0
27objstream.Type = 2
28objstream.Charset = Cset
29BytesToBstr = objstream.ReadText
30objstream.Close
31set objstream = nothing
32End Function
33
34txtURL=server.MapPath("../index.asp")
35
36sText = getHTTPPage(txtURL)
37
38Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
39filename="../index.htm"
40Set openFile=FileObject.OpenTextfile(server.mapPath(filename),2,true) 'true为不存在自行建立
41openFile.writeline(sText)
42Set OpenFile=nothing
1<script>
2alert("静态网页生成完毕");
3history.back();
4</script>
方法二:
resourcefile=server.MapPath("../index.asp")
targetfile=server.MapPath("../index.htm")
Set html = Server.CreateObject("CDO.Message")
html.CreateMHTMLBody resourcefile,31
indexcode=html.HTMLBody
Set html = Nothing
if instr(indexcode,"
")<=0 then
response.Write("首页生成失败")
response.End()
else
Set oFileSys = Server.CreateObject("Scripting.FileSystemObject")
Set outfile=oFileSys.CreateTextFile(targetfile)
outfile.WriteLine indexcode
outfile.close
Set outfile=nothing
set oFileSys=nothing
response.Write("首页生成完毕!")
end if