求教:有没有办法用ASP自动读取某网址的“源文件”保存到文件中。
急问一个问题:有没有办法用ASP自动读取某网址(如www.baidu.com)的源文件(就是IE的“查看”下的那个“源文件”),然后保存到ASP的服务器中?如果有怎么做?(告诉我具体操作过程,不包括存到ASP的服务器中)。麻烦赐教,谢谢。
参考答案:<%
function SaveFile(LocalFileName,RemoteFileUrl)
Dim Ads, Retrieval, GetRemoteData
On Error Resume Next
Set Retrieval = Server.CreateObject("Microso" & "ft.XM" & "LHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject("Ado" & "db.Str" & "eam")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile Server.MapPath(LocalFileName), 2
.Cancel()
.Close()
End With
Set Ads=nothing
if err <> 0 then
SaveFile = false
err.clear
else
SaveFile = true
end if
End function
%>
<%
'---------你要保存的文件目录及名称----
StrName="/index.html"
'-------------------------------------
'---------你要获取的页面路径----------
indexurl=""
if SaveFile(""&StrName&"",""&indexurl&"")=True then
Response.Write indexurl
response.Write "<font color=blue>页面获取&保存成功</font>"
Else
Response.Write indexurl
response.Write "<font color=red>页面获取&保存失败</font>"
End If
%>
参考资料: