看过一篇关于下载网页中图片的文章,它只能下载以http头的图片,我做了些改进,可以下载网页中的所有连接资源,并按照网页中的目录结构建立本地目录,存放资源。
download.asp?url=你要下载的网页
download.asp代码如下
<%
server.scripttimeout=9999
function savetofile(from,tofile)
on error resume next
dim geturl,objstream,imgs
geturl=trim(from)
mybyval=gethttpstr(geturl)
set objstream = server.createobject("adodb.stream")
objstream.type =1
objstream.open
objstream.write mybyval
objstream.savetofile tofile,2
objstream.close()
set objstream=nothing
if err.number<>0 then err.clear
end function
function geturlencodel(byval url)中文文件名转换
dim i,code
geturlencodel=""
if trim(url)="" then exit function
for i=1 to len(url)
code=asc(mid(url,i,1))
if code<0 then code = code + 65536
if code>255 then
geturlencodel=geturlencodel&"%"&left(hex(code),2)&"%"&right(hex(code),2)
else
geturlencodel=geturlencodel&mid(url,i,1)
end if
next
end function
function gethttppage(url)
on error resume next
dim http
set http=server.createobject("msxml2.xmlhttp")
http.open "get",url,false
http.send()
if http.readystate<>4 then exit function
gethttppage=bytes2bstr(http.responsebody)
set http=nothing
if err.number<>0 then err.clear
end function
