<%
If request("d")="" Then
Response.Redirect "myalexa.asp?d=xamq.com"
End If
wd=Request("d")
on error resume next
'远程截取函数开始
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
        t = GetBody(Path)
        getHTTPPage=BytesToBstr(t,"UTF-8")
End function

Function GetBody(url) 
        on error resume next
        Set Retrieval = CreateObject("Microsoft.XMLHTTP") 
 	Retrieval.SetTimeOuts 500,500,500,1000
'setTimeouts的参数顺序也是固定的，按顺序为：域名解析超时时间（resolveTimeout）、连接超时时间（connectTimeout）、数据发送超时时间（sendTimeout）、数据接收超时时间（receiveTimeout）。
        
        With Retrieval 
        .Open "Get", url, False, "", "" 
        .Send 
        GetBody = .ResponseBody
        End With 
        Set Retrieval = Nothing 
End Function

Function BytesToBstr(body,Cset)
        dim objstream
        set objstream = Server.CreateObject("ado"&"db.stream")
        objstream.Type = 1
        objstream.Mode =3
        objstream.Open
        objstream.Write body
        objstream.Position = 0
        objstream.Type = 2
        objstream.Charset = Cset
        BytesToBstr = objstream.ReadText 
        objstream.Close
        set objstream = nothing
End Function
Function Newstring(wstr,strng)
        Newstring=Instr(lcase(wstr),lcase(strng))
        if Newstring<=0 then Newstring=Len(wstr)
End Function

Function fReplace(ByVal szStr)
Dim objRegEx
Dim szResult
Set objRegEx = New RegExp
objRegEx.IgnoreCase = False
objRegEx.Global=True
objRegEx.Pattern = "[^0-9]"
szResult = objRegEx.Replace(szStr,"")
Set objRegEx = Nothing
fReplace = szResult
End Function

Function del(str)
    str=replace(str,"<POPULARITY URL=""","")
    str=replace(str,"/"" TEXT=""","")
    str=replace(str,"""/>","")
    str=replace(str," ","")
del=str
End Function
dim wd
wd=Request("d")
'截取网址
url="http://data.alexa.com/data/?cli=10&dat=snba&ver=7.0&url="&wd
        wstr=getHTTPPage(url)

%>
<html><head>
<title><%=Request("d")%>的alexa综合排名查询结果 | 安美奇网站导航 xamq.com</title>
<meta name="robots" content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="Copyright 2007 netsoz.com" name="Copyright" />
<meta content="Hans He" name="Author">
<style type="text/css">
body{
margin:0px;COLOR:#529252;FONT-SIZE:11px;FONT-weight:bold;TEXT-DECORATION: none; font-family:"Georgia", "Arial";}
A:link,A:visited { COLOR: #0066CC; FONT-SIZE: 12px; font-weight:bold;TEXT-DECORATION:underline;}
A:active,A:hover{COLOR:#FF3300;FONT-SIZE: 12px; font-weight:bold;TEXT-DECORATION: underline;}
A.alexarank:link,A.alexarank:visited { COLOR:#529252;FONT-SIZE:11px;FONT-weight:bold;TEXT-DECORATION: none; font-family:"Georgia", "Arial";}
A.alexarank:hover,A.alexarank:active { COLOR:#FF3300;FONT-SIZE:11px;FONT-weight:bold;TEXT-DECORATION: none; font-family:"Georgia", "Arial";}
</style></head><body leftmargin=0 topmargin=0 bgcolor="#FFFFFF">
<div align="center">
<%
'截取数据
set reg=new Regexp
	reg.Multiline=True
	reg.Global=Flase
	reg.IgnoreCase=true
	reg.Pattern="<POPULARITY URL=((.|\n)*?)>"
	Set matches = reg.execute(wstr)
		For Each match1 in matches
			bodypage=fReplace(del(match1.Value))
		Next
Set matches = Nothing
Set reg = Nothing
Response.Write  ("<a href=""http://www.xamq.com/tj/alexa/?url="&wd&""" target=""_blank"" title="""&bodypage&"&#10;"&wd&""">"&bodypage&"</a>")
%>
</div></body></html> 