|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
强大的可扩展性。ASP具有强大的扩展性,可以实现与多种网络、硬件设备的连接:通过专用的通讯线路远程接入企业;通过远程拨号服务器为远程拨号客户提供服务;通过WAP为移动电话互联网客户服务。程序|网页|下载|下载看过一篇关于下载网页中图片的文章,它只能下载以http头的图片,我做了些改善,能够下载网页中的一切毗连资本,并依照网页中的目次布局创建当地目次,寄存资本。
download.asp?url=你要下载的网页
download.asp代码以下:
<%
Server.ScriptTimeout=9999
functionSaveToFile(from,tofile)
onerrorresumenext
dimgeturl,objStream,imgs
geturl=trim(from)
Mybyval=getHTTPstr(geturl)
SetobjStream=Server.CreateObject("ADODB.Stream")
objStream.Type=1
objStream.Open
objstream.writeMybyval
objstream.SaveToFiletofile,2
objstream.Close()
setobjstream=nothing
iferr.number<>0thenerr.Clear
endfunction
functiongeturlencodel(byvalurl)中文文件名转换
Dimi,code
geturlencodel=""
iftrim(Url)=""thenexitfunction
fori=1tolen(Url)
code=Asc(mid(Url,i,1))
ifcode<0Thencode=code+65536
Ifcode>255Then
geturlencodel=geturlencodel&"%"&Left(Hex(Code),2)&"%"&Right(Hex(Code),2)
else
geturlencodel=geturlencodel&mid(Url,i,1)
endif
next
endfunction
functiongetHTTPPage(url)
onerrorresumenext
dimhttp
sethttp=Server.createobject("Msxml2.XMLHTTP")
Http.open"GET",url,false
Http.send()
ifHttp.readystate<>4thenexitfunction
getHTTPPage=bytes2BSTR(Http.responseBody)
sethttp=nothing
iferr.number<>0thenerr.Clear
endfunction
Functionbytes2BSTR(vIn)
dimstrReturn
dimi,ThisCharCode,NextCharCode
strReturn=""
Fori=1ToLenB(vIn)
ThisCharCode=AscB(MidB(vIn,i,1))
IfThisCharCode<&H80Then
strReturn=strReturn&Chr(ThisCharCode)
Else
NextCharCode=AscB(MidB(vIn,i+1,1))
strReturn=strReturn&Chr(CLng(ThisCharCode)*&H100+CInt(NextCharCode))
i=i+1
EndIf
Next
bytes2BSTR=strReturn
EndFunction
functiongetFileName(byvalfilename)
ifinstr(filename,"/")>0then
fileExt_a=split(filename,"/")
getFileName=lcase(fileExt_a(ubound(fileExt_a)))
ifinstr(getFileName,"?")>0then
getFileName=left(getFileName,instr(getFileName,"?")-1)
endif
else
getFileName=filename
endif
endfunction
functiongetHTTPstr(url)
onerrorresumenext
dimhttp
sethttp=server.createobject("MSXML2.XMLHTTP")
Http.open"GET",url,false
Http.send()
ifHttp.readystate<>4thenexitfunction
getHTTPstr=Http.responseBody
sethttp=nothing
iferr.number<>0thenerr.Clear
endfunction
FunctionCreateDIR(ByValLocalPath)创建目次的程序,假如有多级目次,则一级一级的创立
OnErrorResumeNext
LocalPath=Replace(LocalPath,"","/")
SetFileObject=server.CreateObject("Scripting.FileSystemObject")
patharr=Split(LocalPath,"/")
path_level=UBound(patharr)
ForI=0Topath_level
IfI=0Thenpathtmp=patharr(0)&"/"Elsepathtmp=pathtmp&patharr(I)&"/"
cpath=Left(pathtmp,Len(pathtmp)-1)
IfNotFileObject.FolderExists(cpath)ThenFileObject.CreateFoldercpath
Next
SetFileObject=Nothing
IfErr.Number<>0Then
CreateDIR=False
Err.Clear
Else
CreateDIR=True
EndIf
EndFunction
functionGetfileExt(byvalfilename)
fileExt_a=split(filename,".")
GetfileExt=lcase(fileExt_a(ubound(fileExt_a)))
endfunction
functiongetvirtual(str,path,urlhead)
ifleft(str,7)="http://"then
url=str
elseifleft(str,1)="/"then
start=instrRev(str,"/")
ifstart=1then
url="/"
else
url=left(str,start)
endif
url=urlhead&url
elseifleft(str,3)="../"then
str1=mid(str,inStrRev(str,"../")+2)
ar=split(str,"../")
lv=ubound(ar)+1
ar=split(path,"/")
url="/"
fori=1to(ubound(ar)-lv)
url=url&ar(i)
next
url=url&str1
url=urlhead&url
else
url=urlhead&str
endif
getvirtual=url
endfunction
示例代码
dimdlpath
virtual="/downweb/"
truepath=server.MapPath(virtual)
ifrequest("url")<>""then
url=request("url")
fn=getFileName(url)
urlhead=left(url,(instr(replace(url,"//",""),"/")+1))
urlpath=replace(left(url,instrRev(url,"/")),urlhead,"")
strContent=getHTTPPage(url)
mystr=strContent
SetobjRegExp=NewRegexp
objRegExp.IgnoreCase=True
objRegExp.Global=True
objRegExp.Pattern="(src|href)=.[^>]+?"
SetMatches=objRegExp.Execute(strContent)
ForEachMatchinMatches
str=Match.Value
str=replace(str,"src=","")
str=replace(str,"href=","")
str=replace(str,"""","")
str=replace(str,"","")
filename=GetfileName(str)
getRet=getVirtual(str,urlpath,urlhead)
temp=Replace(getRet,"//","**")
start=instr(temp,"/")
endt=instrRev(temp,"/")-start+1
ifstart>0then
repl=virtual&mid(temp,start)&""
response.Writerepl&"<br>"
mystr=Replace(mystr,str,repl)
dir=</p>asp对于服务器的要求较高,一般的服务器如果访问量一大就垮了,不得不重启。 |
|