日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

获取网站Alexa排名数值的方法

發布時間:2025/5/22 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取网站Alexa排名数值的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

??網絡上有很多文章介紹如何自動抓取網站的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

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的获取网站Alexa排名数值的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。