asp通用采集函数冗余版可以保存文件到本地
程序员文章站
2022-06-21 22:52:14
<% '名称:asp通用采集函数冗余版,要精品版的有心人自己改 '作者:柳永法 '日期:2007-6-23 function gethttppage(pat...
<%
'名称:asp通用采集函数冗余版,要精品版的有心人自己改
'作者:柳永法
'日期:2007-6-23
function gethttppage(path)
t = getbody(path)
gethttppage = bytestobstr(t, "gb2312")
end function
function getbody(url)
on error resume next
set xmlhttp = createobject("microsoft.xmlhttp")
with xmlhttp
.open "get", url, false, "", ""
.send
.waitforresponse 1000
getbody = .responsebody
end with
set xmlhttp = nothing
end function
function bytestobstr(body, cset)
on error resume next
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 gethttpimg(url)
on error resume next
dim xmlhttp
set xmlhttp = server.createobject("msxml2.xmlhttp")
xmlhttp.open "get", url, false
xmlhttp.send()
if xmlhttp.status<>200 then exit function
gethttpimg = xmlhttp.responsebody
set xmlhttp = nothing
if err.number<>0 then err.clear
end function
function save2local(from, tofile)
dim geturl, objstream, imgs
geturl = trim(from)
imgs = gethttpimg(geturl)
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.open
objstream.write imgs
objstream.savetofile tofile, 2
objstream.close()
set objstream = nothing
end function
%>
<%
nowdir = server.mappath("/")
call save2local("http://www.baidu.com/img/logo.gif", nowdir & "baidulogo.gif")
call save2local("http://flash.jninfo.net/images/banner.swf", nowdir & "banner.swf")
call save2local("//www.jb51.net.com/", nowdir & "jb51.htmll")
response.write gethttppage("//www.jb51.net/")
%>
'名称:asp通用采集函数冗余版,要精品版的有心人自己改
'作者:柳永法
'日期:2007-6-23
function gethttppage(path)
t = getbody(path)
gethttppage = bytestobstr(t, "gb2312")
end function
function getbody(url)
on error resume next
set xmlhttp = createobject("microsoft.xmlhttp")
with xmlhttp
.open "get", url, false, "", ""
.send
.waitforresponse 1000
getbody = .responsebody
end with
set xmlhttp = nothing
end function
function bytestobstr(body, cset)
on error resume next
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 gethttpimg(url)
on error resume next
dim xmlhttp
set xmlhttp = server.createobject("msxml2.xmlhttp")
xmlhttp.open "get", url, false
xmlhttp.send()
if xmlhttp.status<>200 then exit function
gethttpimg = xmlhttp.responsebody
set xmlhttp = nothing
if err.number<>0 then err.clear
end function
function save2local(from, tofile)
dim geturl, objstream, imgs
geturl = trim(from)
imgs = gethttpimg(geturl)
set objstream = server.createobject("adodb.stream")
objstream.type = 1
objstream.open
objstream.write imgs
objstream.savetofile tofile, 2
objstream.close()
set objstream = nothing
end function
%>
<%
nowdir = server.mappath("/")
call save2local("http://www.baidu.com/img/logo.gif", nowdir & "baidulogo.gif")
call save2local("http://flash.jninfo.net/images/banner.swf", nowdir & "banner.swf")
call save2local("//www.jb51.net.com/", nowdir & "jb51.htmll")
response.write gethttppage("//www.jb51.net/")
%>