获取网页中资源的相对路径

dim xurl
xurl="http://www.chinadxscy.com/news/html/20070628201930.html"
xstr="../../images/stm31.js"
urlhead=left(xurl,(instr(replace(xurl,"//",""),"/")+1))
urlpath=replace(left(xurl,instrRev(xurl,"/")),urlhead,"")
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)
  response.Write(str1)
  ar=split(str,"../")
  response.Write(ar(1))
  lv=ubound(ar)+1
  ar=split(path,"/")
  url=""
  response.Write(lv)
  response.Write(ubound(ar)-lv)
  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
response.Write(getvirtual(xstr,urlpath,urlhead))
说明:xstr是xurl中的资源,最终获得xstr的绝对路径为http://www.chinadxscy.com/images/stm31.js
posted @ 2007-07-06 11:46  老保  Views(441)  Comments(0)    收藏  举报