帐号: 密码:
// 设为首页 // 收藏本站 // 请您留言 // 网址导航
远方教程-满足你的求知欲!
站内搜索:
HTML ASP PHP CSS DIV Dreamweaver Photoshop Word Excel PPT SEO技巧
您当前位置:网站首页 >> ASP教程 >> ASP网络编程 >> 阅读文章

ASP网络篇:4.2 用ASP编写下载网页中所有资源的程序

来源:远方教程 作者:远方教程 发布时间:2014-11-09 查看次数:4271 访问[新版]

Function CreateDIR(ByVal LocalPath) ’建立目录的程序,如果有多级目录,则一级一级的创建
 On Error Resume Next
 LocalPath = Replace(LocalPath, "\", "/")
 Set FileObject = server.CreateObject("Scripting.FileSystemObject")
 patharr = Split(LocalPath, "/")
 path_level = UBound(patharr)
 For I = 0 To path_level
  If I = 0 Then pathtmp = patharr(0) & "/" Else pathtmp = pathtmp & patharr(I) & "/"
   cpath = Left(pathtmp, Len(pathtmp) - 1)
  If Not FileObject.FolderExists(cpath) Then FileObject.CreateFolder cpath
 Next
 Set FileObject = Nothing
 If Err.Number <> 0 Then
  CreateDIR = False
  Err.Clear
 Else
  CreateDIR = True
 End If
End Function

function GetfileExt(byval filename)
 fileExt_a=split(filename,".")
 GetfileExt=lcase(fileExt_a(ubound(fileExt_a)))
end function

function getvirtual(str,path,urlhead)
 if left(str,7)="http://" then
  url=str
 elseif left(str,1)="/" then
  start=instrRev(str,"/")
  if start=1 then
   url="/"
  else
   url=left(str,start)
  end if
  url=urlhead&url
  elseif left(str,3)="../" then
  str1=mid(str,inStrRev(str,"../")+2)
  ar=split(str,"../")
  lv=ubound(ar)+1
  ar=split(path,"/")
  url="/"
  for i=1 to (ubound(ar)-lv)
   url=url&ar(i)
  next
  url=url&str1
  url=urlhead&url
 else
  url=urlhead&str
 end if
 getvirtual=url
end function
’示例代码
dim dlpath

virtual="/downweb/"
truepath=server.MapPath(virtual)
if request("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
 Set objRegExp = New Regexp
 objRegExp.IgnoreCase = True
 objRegExp.Global = True
 objRegExp.Pattern = "(src|href)=.[^\>]+? "
 Set Matches =objRegExp.Execute(strContent)
 For Each Match in Matches
  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
  if start>0 then
   repl=virtual&mid(temp,start)&" "
   ’response.Write repl&"<br>"
   mystr=Replace(mystr,str,repl)

  dir=mid(temp,start,endt)
  temp=truepath&Replace(dir,"/","\")
  CreateDir(temp)
  ’response.Write getRet&"||"&temp&filename&"<br><br>"
  SaveToFile getRet,temp&filename
 end if
Next
set Matches=nothing
end if

第1页 第2页
打印 打印 | 关闭 关闭 评论
相关文章
图片新闻
站内搜索  
搜索
猜您喜欢  
最新更新  
阅读排行  
关于我们 | 联系方式 | 大事记 | 免责声明 | | 给我留言
部分广告源自金山联盟2345联盟 QQ咨询 站长之家QQ群:232617873
Copyright 2024 远方教程 © All Rights Reserved.

回顶部