asp通用采集函数冗余版可以保存文件到本地

时间:2021-05-28

<%
'名称:asp通用采集函数冗余版,要精品版的有心人自己改
'作者:柳永法
'日期:2007-6-23
FunctiongetHTTPPage(Path)
t=GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
EndFunction

FunctionGetBody(url)
OnErrorResumeNext
Setxmlhttp=CreateObject("Microsoft.XMLHTTP")
Withxmlhttp
.Open"Get",url,False,"",""
.Send
.waitForResponse1000
GetBody=.ResponseBody
EndWith
Setxmlhttp=Nothing
EndFunction

FunctionBytesToBstr(Body,Cset)
OnErrorResumeNext
Dimobjstream
Setobjstream=Server.CreateObject("adodb.stream")
objstream.Type=1
objstream.Mode=3
objstream.Open
objstream.WriteBody
objstream.Position=0
objstream.Type=2
objstream.Charset=Cset
BytesToBstr=objstream.ReadText
objstream.Close
Setobjstream=Nothing
EndFunction

FunctiongetHTTPimg(url)
OnErrorResumeNext
Dimxmlhttp
Setxmlhttp=server.CreateObject("MSXML2.XMLHTTP")
xmlhttp.Open"GET",url,false
xmlhttp.send()
Ifxmlhttp.Status<>200ThenExitFunction
getHTTPimg=xmlhttp.responseBody
Setxmlhttp=Nothing
IfErr.Number<>0ThenErr.Clear
EndFunction

FunctionSave2Local(from,tofile)
Dimgeturl,objStream,imgs
geturl=Trim(from)
imgs=gethttpimg(geturl)
SetobjStream=Server.CreateObject("ADODB.Stream")
objStream.Type=1
objStream.Open
objstream.Writeimgs
objstream.SaveToFiletofile,2
objstream.Close()
Setobjstream=Nothing
EndFunction

%>

<%
NowDir=server.mappath("/")
CallSave2Local("http:///",NowDir&"jb51.htmll")
response.WritegetHTTPPage("https://www.jb51.net/")
%>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章