网络上有很多文章介绍如何自动抓取网站的Alexa排名,但是仔细一看发现抓取到的数据(Alexa排名

数值)被Alexa加入了很多干扰元素,如果只是要将数据(Alexa排名数值)显示在页面倒没有什么问题

,若是要对数据进行处理比如将两个网站的排名数值进行比较或者将网站排名数值存入数据库供日后调

用,则要对抓取到的数据进行适当的处理。

以下是本人结合其他网友提供的代码,对抓取到的数据进行处理后获得干干净净的数值的方法。核心

函数代码如下: <%

'// alexa 世界排名的查询页面为:http://www.alexa.com/data/details/traffic_details?q=&Url=

'// 以下函数抓取到含有干扰元素的数据并通过函数对数据进行处理,获得干干净净的Alexa排名数值

Function alexa(str)

url="http://www.alexa.com/data/details/traffic_details?q=&url="&str
strs=str

If IsObjInstalled("AspHTTP.Conn")=true Then
str= getaspHTTPPage(url)
else
str= getHTTPPage(url)
End if

if str="" then
Call Error()
else
   str_=str
   str1=""
    set reg=new Regexp
reg.Multiline=True
reg.Global=True
reg.IgnoreCase=true
str_top="<!--Did you know"
str_bottom="</span>"
reg.Pattern=""&str_top&"((.|\n)*?)"&str_bottom&""
Set matches = reg.execute(str_)
str1=""
For Each match1 in matches
str1=str1&match1.Value&"***"
Next
Set matches = Nothing
Set reg = Nothing

IF str1 <> "" Then
str1 = Replace(str1,"<!--Did you know? Alexa offers this data programmatically.

Visit http://webservices.amazon.com/ for more information about the Alexa Web Information

Service.-->","")
str1 = Replace(str1,"</span>","")
Str_11=split(str1,"<div class=""borderBottom""></div>")
str1 = Str_11(0)
Str_11 = split(str1,"***")
str1_Pan = Str_11(0)
End If

set reg=new Regexp
reg.Multiline=True
reg.Global=True
reg.IgnoreCase=true
str_top="<td class=""traffic"">"
str_bottom="</td>"
reg.Pattern=""&str_top&"((.|\n)*?)"&str_bottom&""
Set matches = reg.execute(str_)
str1=""
For Each match1 in matches
str1=str1&match1.Value&"***"
Next
Set matches = Nothing
Set reg = Nothing

IF str1 <> "" Then
Str_11=split(str1,"***")

End If
End if

'************************************
'************************************
alexa=getcorrectvalue(str1_Pan)
'************************************
'************************************

End Function

'************************************
'此功能函数去除干扰元素
'************************************
function getcorrectvalue(source)
source="|"+source+"|"

while InStr(source,"<")>0
thestart = InStr(source, "<")
theend   = InStr(source, ">")
source = mid(source,1,thestart-1)+right(source,(len(source)-theend))
wend

source=replace(source,"|","")
source=replace(source,",","")
getcorrectvalue=source
end function

'************************************
'************************************

'// <summary>
'// 采用 Microsoft.XMLHTTP 组件采集数据
'// </summary>
Function getHTTPPage(url) 
on error resume next 
dim http 
 set http=Server.createobject("Microsoft.XMLHTTP") 
Http.open "GET",url,false 
Http.send() 
if Http.readystate<>4 then
exit function 
end if 
getHTTPPage=bytes2BSTR(Http.responseBody) 
set http=nothing
if err.number<>0 then err.Clear  
End function

'// <summary>
'// 采用 ADODB.Stream 处理采集到的数据,把二进制的文件转成文本字符
'// </summary>
Function Bytes2bStr(vin)
  Dim BytesStream,StringReturn
  Set BytesStream = Server.CreateObject("ADODB.Stream")
  BytesStream.Type = 2
  BytesStream.Open
  BytesStream.WriteText vin
  BytesStream.Position = 0
  BytesStream.Charset = "GB2312"
  BytesStream.Position = 2
  StringReturn =BytesStream.ReadText
  BytesStream.close
  Set BytesStream = Nothing
  Bytes2bStr = StringReturn
End Function

'// <summary>
'// 采用 AspHTTP.Conn 组件采集数据
'// </summary>
Function getaspHTTPPage(url)
    if url="" then
exit function 
    end if 
    Set HttpObj = Server.CreateObject("AspHTTP.Conn")

'设置代理服务器,通过代理上网的用户需要设置此选项
If ProxyIP=1 Then
HttpObj.Proxy="192.168.5.254:808"
end if

HTTPObj.TimeOut = 45
HttpObj.Url = url
HttpObj.RequestMethod = "GET"
getaspHTTPPage = HttpObj.GetURL
    set HttpObj=nothing
End function

'//<summary>
'//检查组件,采用xmlhttp抓取网页还是AspHTTP
'//</summary>

Function IsObjInstalled(strClassString)
 On Error Resume Next
 IsObjInstalled = False
 Err = 0
 Dim xTestObj
 Set xTestObj = Server.CreateObject(strClassString)

If 0 = Err Then
If AspHttpOpen=1 Then
IsObjInstalled = True
'Response.write "当前组件 ASPHTTP"
Else
IsObjInstalled = False
'Response.write "当前组件 XMLHTTP"
End If
 Else
IsObjInstalled = False
'Response.write "当前组件 XMLHTTP"
 End If

Set xTestObj = Nothing
 Err = 0
 
End Function

Sub Error()
response.write "<BR>  抓取不到数据-可能是因为网络原因不能访问站点<BR><a

href=javascript:location.reload();>重试</a>"
response.end
End Sub

%>

调用方法:

<%
response.write alexa("http://blog.sina.com.cn/u/1086421675")
%>

<%=alexa("http://blog.sina.com.cn/u/1086421675")%>

转载于:https://blog.51cto.com/naiht/245487

获取网站Alexa排名数值的方法相关推荐

  1. alexa api php,PHP通过Alexa官方API获取网站Alexa排名 - 米扑博客

    Alexa 接口 Alexa的XML API接口是:http://data.alexa.com/data?cli=10&url=YOUR_DOMAIN_URL 查询结果如下: 如果想获取更多的 ...

  2. alexa api php,通过官方 API 获取网站 Alexa 排名

    Alexa 官方提供了 XML API 接口工具,地址是:http://data.alexa.com/data?cli=10&url=%YOUR_URL%.如果想获取更多的数据可以用:http ...

  3. 提高网站Alexa排名的正确方法

    各位站长都了解,很多人衡量一个网站的标准就是用Alexa来衡量的,虽然这个东西存在很多的不合理性,但是现在一直在用.     所以提高Alexa成为新站站长比较头疼的事情.     Alexa统计是统 ...

  4. 用jquery的ajax功能获取网站alexa的方法

    用jquery的ajax功能获取网站alexa的方法: 获取网站alexa的方法其实就是利用了jquery的ajax功能,获取远程的xml文件,读取指定内容的代码,从而获取网站的alexa排名. 代码 ...

  5. Alexa排名是什么意思?对于网站Alexa排名的详细解说篇

    网络已经成为新世纪商家争夺的销售渠道,众所周知,5a资源网就是一个成功的例子,5a资源网就是为了更好的服务大众,全称为5a资源网络科技发展有限公司,该公司是网络资源服务商,是一家多年来从事网络资源共享 ...

  6. 提高网站Alexa排名最有效的八种方法

    当我们知道Alexa是什么,也知道为什么要提高Alexa之后,接下来的重点,就是谈谈如何提高Alexa排名. 我这里所讲的绝不会是某种的方法.比如你用搜索来搜一下"Alexa 刷" ...

  7. 如何让新建网站alexa排名进入10万大关

    Alexa作为网站访问量的一个排名指标,不仅能说明一个网站的访问量,还能在一定程度上反应网站域名的权重.与人交换链接时.申请广告时等都会看你的域名alexa排名!如果你的域名alexa排名还在50万以 ...

  8. python获取网站window全局对象或方法的返回值

    本章教程,主要介绍如何使用python获取网站中的window全局对象或方法的返回值. 目录 1.浏览器运行结果 2.程序代码 3.程序运行结果 1.浏览器运行结果 2.程序代码 #!/usr/bin ...

  9. 教你几个提升网站快速排名的好方法

    很多seo技术人员认为,网站关键词排名是和文章内容有决定性的作用,其实并不是这样的,文章内容这块是起到了非常重要的作用,但是网站想要做到快速排名却重点不是它,也许你会看到一些网站内容是极其少的,但是他 ...

最新文章

  1. python代码判断两棵二叉树是否相同
  2. 查看mysql版本的四种方法
  3. 从 Windows 切换到 Mac,不能错过这9条Tips
  4. python提高办公效率-用Python的这3个优点,让工作效率提升一倍
  5. Ubuntu自带pdf查看器不能显示中文解决问题
  6. python2019慕课答案_中国大学慕课mooc2020Python编程基础章节测试答案
  7. java运行构建期间出错_构建和运行Java 8支持
  8. linux xargs命令,xargs 命令教程
  9. java peek方法_Java ArrayDeque peek()方法与示例
  10. BBED for PostgreSQL
  11. T-SQL语言(一)
  12. ubuntu16.xxx安装mysql5.0项目迁移环境搭建
  13. 计算机控制实验 实验十,自控计控原理实验箱
  14. C++实现【启发式搜索】算法
  15. Android NVidia Tegra2平台Camera架构浅析
  16. 数据结构----线性表
  17. 【密码学】Java课设-文件加密系统(适用于任何文件)
  18. 这些常见的漏洞和修复方法你知道吗?
  19. excel表格中隔行自动换颜色?
  20. 二叉树——根据 中序 和 层序 建树,超详讲解。

热门文章

  1. 如何在Linux中查看所有正在运行的进程
  2. 【JavaScript】document对象属性
  3. Windows Mobile常用程序代码(串口、图象、网络、3D、数据库、音频视频等等)
  4. c#资源管理器【转】
  5. js的concat方法的使用
  6. Java 计算学生的考试成绩
  7. C语言 读取字符串数组中的字符串并获取字符串的长度
  8. Python3 requests post 中文乱码 UnicodeEncodeError: ‘latin-1‘ codec can`t encode characters in ……
  9. DS博客作业08--课程总结
  10. 前端相对路径 与后端相对路径的区分