思路:
用xmlhttp来判断R开头的文件是否存在。然后根据返回成功与否,再转向

解决方案 »

  1.   

    to net_lover:大侠,把脚本写出来好么
    to weidegong:最好是自动搜索。
      

  2.   

    试一下这个ASP文件,你也许需要用第二个oRegExp.Pattern,而且需要改动其中的模式<%@ Language="VBSCRIPT"%>
    <%Option Explicit%>
    <%
    DIM xmlhttp, matches,sURL,sHomeURL,sContent, oRegExp, oMatch, nIndex, nCount, sPath
    sURL = "http://msdn.microsoft.com"
    sHomeURL = "http://www.microsoft.com"set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.Open "GET",sURL, FALSE
    xmlhttp.SendsContent = xmlhttp.ResponseText
    set oRegExp = new RegExp
    oRegExp.Pattern = "<a\s+href=[""']?([^""'\s]+)[""']?\s*[^>]*>"
    'oRegExp.Pattern = "<a\s+href=[""']?(r[^""'\s]+)[""']?\s*[^>]*>"
    oRegExp.IgnoreCase = TRUE
    oRegExp.Global = TRUE
    set matches = oRegExp.Execute(sContent)
    if matches.Count = 0 then
      Response.Redirect sHomeURL
    else
      Randomize
      nIndex = Int(matches.Count * RND())
      set oMatch = matches(nIndex)
      sPath = oMatch.SubMatches(0)
      if Instr(sPath,"http://") = 0 then
            if Left(sPath,1) = "/" then
    sPath = sHomeURL & sPath
    else
    sPath = sHomeURL & "/" & sPath
    end if
      end if
      Response.Redirect sPath
    end if'nCount = 0
    'for each oMatch in matches
     ' nCount = nCount + 1
      'Response.Write "*****" & nCount & "*****<BR>"
      'Response.Write oMatch.Value & "<BR>"
      'Response.Write "href:" & oMatch.SubMatches(0) & "<BR>"
      'Response.Write "**********<BR><BR>"
    'next
    %>
      

  3.   

    这里最主要的是要取得那个HTML文件,我这里用的是MSXML解释器里的组件,
    set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.Open "GET",sURL, FALSE
    xmlhttp.Send
    sContent = xmlhttp.ResponseText然后是用正则表达式得出所有的连接,
    set oRegExp = new RegExp
    oRegExp.Pattern = "<a\s+href=[""']?([^""'\s]+)[""']?\s*[^>]*>"
    'oRegExp.Pattern = "<a\s+href=[""']?(r[^""'\s]+)[""']?\s*[^>]*>"
    oRegExp.IgnoreCase = TRUE
    oRegExp.Global = TRUE
    set matches = oRegExp.Execute(sContent)然后是随机取其中一个
    Randomize
    nIndex = Int(matches.Count * RND())
    set oMatch = matches(nIndex)
    sPath = oMatch.SubMatches(0)