asp读取远程页面生成静态页的方法

<%

Function getHTTPPage(url)  ‘读取url
  dim Http 
  set Http=server.createobject("MSXML2.XMLHTTP") 
  Http.open "GET",url,false 
  Http.send() 
  if Http.readystate<>4 then 
   exit function 
  end if 
  getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") 
  set http=nothing 
  if err.number<>0 then err.Clear 
 end function

 Function BytesToBstr(body,Cset)  ‘字符转换
  dim objstream 
  set objstream = Server.CreateObject("adodb.stream") 
  objstream.Type = 1 
  objstream.Mode =3 
  objstream.Open 
  objstream.Write body 
  objstream.Position = 0 
  objstream.Type = 2 
  objstream.Charset = Cset 
  BytesToBstr = objstream.ReadText 
  objstream.Close 
 set objstream = nothing  
 End Function 

 Function CreateStatic(txtURL,FileName)  ‘写入文件
  sText = getHTTPPage(txtURL) 
  Set FileObject=Server.CreateObject("Scripting.FileSystemObject") 
  Set openFile=FileObject.OpenTextfile(server.mapPath(Filename),2,true) ‘true为不存在自行建立 
  openFile.writeline(sText) 
  Set OpenFile=nothing
 End Function
 
 Function CreateIndex()
  Response.Write("<span id=""info"">首页生成中,请稍后…</span>")
  Response.Flush()
  TxtUrl = http://www.xiaoyaoking.com
  FilePath = "Test.html"
  Call CreateStatic(TxtUrl,FilePath)
  Response.Write("<script>document.getElementById(‘info’).innerHTML=’静态生成成功!完成时间:"&Now&"’;</script>")
 End Function

%>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注