将asp重写url(html)页面

来源:互联网 发布:自动采集视频网站源码 编辑:程序博客网 时间:2024/04/29 10:05
 
内容摘要:%Function GetPage(url) 获得文件内容dim RetrievalSet Retrieval = CreateObject(Microsoft.XMLHTTP) With Retrieval .Open Get, url, False , , .Send GetPage = BytesToBstr(.ResponseBody)End With Set Retrieval = Nothing End FunctionFunction BytesToBstr(body)dim<script type="text/javascript"><!--google_ad_client = "pub-2023897064603208";google_ad_width = 468;google_ad_height = 60;google_ad_format = "468x60_as";google_ad_type = "text";google_ad_channel = "";google_color_border = "f2f2f2";google_color_bg = "f2f2f2";google_color_link = "000000";google_color_text = "000000";google_color_url = "000000";//--></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>


 

<%
Function GetPage(url)
 '获得文件内容
 dim Retrieval
 Set Retrieval = CreateObject("Microsoft.XMLHTTP")
 With Retrieval
  .Open "Get", url, False ', "", ""
  .Send
  GetPage = BytesToBstr(.ResponseBody)
 End With
 Set Retrieval = Nothing
End Function

Function BytesToBstr(body)
 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 = "GB2312"
 BytesToBstr = objstream.ReadText
 objstream.Close
 set objstream = nothing
End Function

on error resume next
Url="http://www.sina.com.cn"'要读取的页面地址
response.write "开始更新首页..."
wstr = GetPage(Url)

'response.write(wstr)
Set fs=Server.CreateObject("Scripting.FileSystemObject")

'if not MyFile.FolderExists(server.MapPath("/html/")) then
'MyFile.CreateFolder(server.MapPath("/html/"))'
'end if

'要存放的页面地址
dizhi=server.MapPath("index.htm")
If (fs.FileExists(dizhi)) Then
fs.DeleteFile(dizhi)
End If

Set CrFi=fs.CreateTextFile(dizhi)
Crfi.Writeline(wstr)
set CrFi=nothing
set fs=nothing
response.write "...<font color=red>更新完成!</font>"
%>


代码算是最简单的,直接保存成一个asp文件即可,只要把URL(要转化的asp地址)和dizhi(要保存的html地址)设置好就可以了,一般这两个文件在同一个目录,才能保证图片或者CSS、js起作用。