分析URL中关键字(从阿江统计偷的)
2008-06-07 16:45
253 查看
<%@ Language=VBs cript %>
<%
' 从URL中获取关键词
function findKeystr(urlstr)
dim regEx,vKey,vP,findKeystr1
findkeystr=""
vP = "(?:yahoo.+?[/?|&]p=|openfind.+&q=|google.+[/?|&]q=|lycos.+?query=|aol.+?query=|onseek.+?keyword=|search/.tom.+?word=|search/.qq/.com.+?word=|zhongsou/.com.+?word=|search/.msn/.com.+?q=|yisou/.com.+?p=|sina.+?word=|sina.+?query=|sina.+?_searchkey=|sohu.+?word=|sohu.+?key_word=|sohu.+?query=|163.+?q=|baidu.+[/?|&]wd=|3721/.com.+?name=|Alltheweb.+?q=)([^&]*)"
set regEx=new regexp
regEx.Global = true
regEx.IgnoreCase = true
regEx.Pattern = vP
set Matches = regEx.Execute(urlstr)
for each Match in Matches
' 没有使用subMatches是因为有的服务器可能并没有安装VBS5.5版本
findKeystr1 = regEx.replace(Match.value,"$1")
next
if findKeystr1<> "" then
findkeystr=lcase(decodeURI(findkeystr1))
if findkeystr = "undefined" then
findkeystr = URLDecode(findKeystr1)
end if
end if
end function
' 解开URL编码的函数(这是别人写的,我查到的地方标注为: 来源: CSDN 作者: dyydyy )
Function URLDecode(enStr)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function
Response.write findKeystr("http://www.google.com/search?hl=zh-CN&;q=%E4%B8%AD%E5%9B%BDe%E5%BA%B7&btnG=Google+%E6%90%9C%E7%B4%A2&lr=")
%>
<s cript language="javas cript" runat="server" type="text/javas cript">
//解码URI
function decodeURI(furl){
var a=furl;
try{return decodeURIComponent(a)}catch(e){return 'undefined'};
return '';
}
</s cript>
<%
' 从URL中获取关键词
function findKeystr(urlstr)
dim regEx,vKey,vP,findKeystr1
findkeystr=""
vP = "(?:yahoo.+?[/?|&]p=|openfind.+&q=|google.+[/?|&]q=|lycos.+?query=|aol.+?query=|onseek.+?keyword=|search/.tom.+?word=|search/.qq/.com.+?word=|zhongsou/.com.+?word=|search/.msn/.com.+?q=|yisou/.com.+?p=|sina.+?word=|sina.+?query=|sina.+?_searchkey=|sohu.+?word=|sohu.+?key_word=|sohu.+?query=|163.+?q=|baidu.+[/?|&]wd=|3721/.com.+?name=|Alltheweb.+?q=)([^&]*)"
set regEx=new regexp
regEx.Global = true
regEx.IgnoreCase = true
regEx.Pattern = vP
set Matches = regEx.Execute(urlstr)
for each Match in Matches
' 没有使用subMatches是因为有的服务器可能并没有安装VBS5.5版本
findKeystr1 = regEx.replace(Match.value,"$1")
next
if findKeystr1<> "" then
findkeystr=lcase(decodeURI(findkeystr1))
if findkeystr = "undefined" then
findkeystr = URLDecode(findKeystr1)
end if
end if
end function
' 解开URL编码的函数(这是别人写的,我查到的地方标注为: 来源: CSDN 作者: dyydyy )
Function URLDecode(enStr)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function
Response.write findKeystr("http://www.google.com/search?hl=zh-CN&;q=%E4%B8%AD%E5%9B%BDe%E5%BA%B7&btnG=Google+%E6%90%9C%E7%B4%A2&lr=")
%>
<s cript language="javas cript" runat="server" type="text/javas cript">
//解码URI
function decodeURI(furl){
var a=furl;
try{return decodeURIComponent(a)}catch(e){return 'undefined'};
return '';
}
</s cript>
相关文章推荐
- java, asp 分析各种搜索引擎的关键字,自动识别url 中关键字的编码
- STL MAP及字典树在关键字统计中的性能分析
- 页面访问统计 提取url中的关键字
- 阿江网站访问统计系统设计构思分析
- C#分析搜索引擎URL得到搜索关键字,并判断页面停留时间以及来源页面
- 通过编写Python小程序来统计测试脚本的关键字分析 20160328
- 阿江网站访问统计系统设计构思分析
- 阿江网站访问统计系统设计构思分析
- C# 分析搜索引擎url 得到搜索关键字
- java asp分析各种搜索引擎的关键字,自动识别url 中关键字的编码
- C# 分析搜索引擎url 得到搜索关键字
- STL MAP及字典树在关键字统计中的性能分析
- C# 分析搜索引擎url 得到搜索关键字
- springMVC源码分析--AbstractControllerUrlHandlerMapping(六)
- Excel在统计分析中的应用—第七章—参数估计-总体方差比的估计
- springMVC源码分析--BeanNameUrlHandlerMapping(七)
- 趣话人工智能:Google的adwords关键字分析
- Excel在统计分析中的应用—第八章—假设检验-方差已知下总体均值的双侧检验
- Excel在统计分析中的应用—第五章—统计指数-Part3- 综合指数(现期加权指数(帕氏指数))
- Excel在统计分析中的应用—第八章—假设检验-方差未知且为小样本下的总体均值的双侧检验