当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用asp程序读取网站的alexa世界排名

ASP
ASP中数据库调用中常见错误的现象和解决方法
ASP取出HTML里面的图片地址的函数
关于分页查询和性能问题
利用Asp生成整站静态
用ASP+XMLHTTP编写一个天气预报程序
轻松检测浏览器是否接受Cookies信息
净化网络环境:ASP程序实现过滤脏话
入门:防范SQL注入攻击的新办法
如何对ASP.NET进行性能优化
ASP无法更新ACCESS数据库解决方法
ASP:利用ASP把图片上传到数据库
ASP:用ASP编程实现网络内容快速查找
ASP:用ASP打造一个小型的网页BBS系统
ASP:用Asp编程实现QQ的在线情况查询
通过表单创建word的一个例子
在ASP中轻松实现记录集分页显示
ASP中实现小偷程序的原理和简单示例
ASP:6行代码实现无组件上传
实用篇:用asp实现QQ在线查询
如何轻松打造ASP计数器

ASP 中的 用asp程序读取网站的alexa世界排名


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 89 ::
收藏到网摘: n/a

平时每逢alexa排名更新时,我都需要将所有相关的同类网站的排名整理一下,看一下这些对手网站的排名更新情况。做的多了,也就烦了,虽然也才30多个网站,但一个个看下来也有点累。因此,想能不能用程序来读取他的排名数据。

以前记得在什么网址大全的网站上,一个网站名称后面还有这个网站的世界排名,相信肯定是用程序读取的,不然要是一个个查非累死不可。但是浏览遍了alexa的网站,也没有找到能够直接得到排名数据的方法。虽然它提供了一些代码,如:,但是图片的数字就没办法读取到了。

后来想要不用xmlhttp读它页面,然后截取出那段数字?麻烦是麻烦点,也许可以一试。于是开始查看显示排名的那两页,

以下为引用的内容:

http://www.alexa.com/data/details/@url=www.itlearner.com 和 http://www.alexa.com/data/details/traffic_details@q=!amp;url=www.itlearner.com,查看源文件,搜索"traffic rank for",搜到我网站的排名是这样一段代码:<ti><bbip><traffic><today>4</today></traffic></bbip></ti>5<tprp><pyp><page views rank:><pyp>,</pyp></page views rank:></pyp></tprp><today>7</today><page views per user:><[email protected]><today>6</today></[email protected]></page views per user:><[email protected]><traffic rank for>1</traffic rank for></[email protected]>,扑通,看得这段代码都大了,再找了一下,看到在显示traffic rank:today 1 wk. avg. 3 mos. avg. 3 mos. change那边,前面today和1wk都是用上面那种形式表示的,而到了3 mos也就是最关键的数据那边,确是直接用数字显示的,太好了!

分析了一下前后的代码,发现数据后面的</td><td class="bodybold" align="center" bgcolor="#ffffff"><img这段代码是唯一的,于是开始编程工作。

下面的源代码示例,供大家参考:

以下为引用的内容:

  <% 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)) 输出排名数据

  %>

嘿嘿,以后公司的相关网站排名,就不用再一个一个去查了,只需要把那些网站依此放在程序里,就可以让程序一个一个的读出来了。