平时每逢alexa排名更新时,我都需要将所有相关的同类网站的排名整理一下,看一下这些对手网站的排名更新情况。做的多了,也就烦了,虽然也才30多个网站,但一个个看下来也有点累。因此,想能不能用程序来读取他的排名数据。
以前记得在什么网址大全的网站上,一个网站名称后面还有这个网站的世界排名,相信肯定是用程序读取的,不然要是一个个查非累死不可。但是浏览遍了alexa的网站,也没有找到能够直接得到排名数据的方法。虽然它提供了一些代码,如:,但是图片的数字就没办法读取到了。
下面的源代码示例,供大家参考:
以下为引用的内容:
<% private function bytes2bstr(vin)
dim i, thischrcode, nextchrcode strreturn = "" for i = 1 to lenb(vin)
thischrcode = ascb(midb(vin, i, 1))
if thischrcode < !amp;h80 then strreturn = strreturn !amp; chr(thischrcode)
else nextchrcode = ascb(midb(vin, i 1, 1))
strreturn = strreturn !amp; chr(clng(thischrcode) * !amp;h100 cint(nextchrcode))
i = i 1 end if next bytes2bstr = strreturn end function function geturl(url)
set retrieval = server.createobject("microsoft.xmlhttp")
with retrieval。open "get", url, false, "", ""。send geturl = .responsetext geturl = bytes2bstr(。responsebody)
end with set retrieval = nothing end function
以上是使用xmlhttp读取页面代码的通用代码
function getalexarank(url)
on error resume next dim tempstr,trueurl,x,keystr
trueurl = "http://www.alexa.com/data/details/traffic_details@q=!amp;url=" !amp; url tempstr=geturl(trueurl)
keystr = "</td><td class=""bodybold"" align=""center"" bgcolor=""#ffffff""><img" tempstr = split(tempstr,keystr)(0)
x = instrrev(tempstr,">") 1 tempstr = mid(tempstr,x)
if err then getalexarank=err.description err.clear else getalexarank=tempstr end if end function
以上是读取alexa网站页面,对代码进行分析然后得到排名的数据
以下为引用的内容:
dim url url="www.itlearner.com" 要查询的网址,不要加http:// response.write(getalexarank2(url)) 输出排名数据
%>
嘿嘿,以后公司的相关网站排名,就不用再一个一个去查了,只需要把那些网站依此放在程序里,就可以让程序一个一个的读出来了。