日期:2011-09-05  浏览次数:21169 次

1.通过xmlhttp读取http://client.alexa.com/common/css/scramble.css该页面的内容,当然,我们也可以直接把这个页面保存到本地使用,但是我们不能保证alexa是否会重新修改该css样式,所以我们实时读取http://client.alexa.com/common/css/scramble.css该页面的内容的方案比较可靠点,我们将页面内容存入变量strAlexaCss中。
        2.通过xmlhttp读取http://www.alexa.com/data/details/traffic_details/www.newbooks.com.cn页面内容,alexa在显示排名的地方,会有如下代码<!--Did you know? Alexa offers this data programmatically.  Visit http://aws.amazon.com/awis for more information about the Alexa Web Information Service.-->,所以我们可以截取我们获得页面内容中的字符串,取<!--Did you know? Alexa offers this data programmatically.  Visit http://aws.amazon.com/awis for more information about the Alexa Web Information Service.-->和<!-- google_ad_section_end(name=default) -->之中的内容。这样,我们就获得了:<span class="cfba">22</span><span class="c477">33</span>1,9<span class="cbea">36</span><span class="c120">25</span></span>这样的字符串,保存至变量rankcontent。
        3.我们得到所有的class属性,可以使用strspan=GetArray(rankcontent,"<span class=""","""",false,false)    (其中getArray方法是大多数的采集代码中都有的函数。),并且得到数组aspan=split(strspan,"$Array$")。我们循环aspan这个数组,对于如果aspan(i)在字符串strAlexaCss中存在,则我们将该span标签和其中的内容替换为空,对于span的class不在strAlexaCss中存在的,我们只需要将span的左标签替换掉。这样,我们得到了22</span>1,9</span>25</span></span>这样的字符串。
        4.最后我们将字符串中所有的</span>替换为空,我们就得到了网站排名数据:221,925

以下是引用片段:
<%
’为了支持原创,请保留该处注释,谢谢!
’作者:草上飞
’博客地址:http://blog.linkhelper.cn/
’获取主域名
Function getDomainUrl(url)
    tempurl=replace(url,"http://","")
    if instr(tempurl,"/")>0 then
        tempurl=left(tempurl,instr(tempurl,"/")-1)
    end If
    getDomainurl=tempurl
End Function


Function GetHttpPage(HttpUrl)
   If IsNull(HttpUrl)=True Or Len(HttpUrl)<18 Or HttpUrl="$False$" Then
      GetHttpPage="$False$"
      Exit Function
   End If
   Dim Http
   Set Http=server.createobject("MSXML2.XMLHTTP")
   Http.open "GET",HttpUrl,False
   Http.Send()
   If Http.Readystate<>4 then
      Set Http=Nothing 
      GetHttpPage="$False$"
      Exit function
   End if
   GetHTTPPage=Http.responseText
   Set Http=Nothing
   If Err.number<>0 then
      Err.Clear
   End If
End Function

’==================================================
’函数名:ScriptHtml
’作  用:过滤html标记
’参  数:ConStr&