asp 判断是否为搜索引擎蜘蛛的代码

来源:asp之家 时间:2011-03-10 11:03:00 


代码如下:


<% 
function GetBot() 
'查询蜘蛛 
dim s_agent 
GetBot="" 
s_agent=Request.ServerVariables("HTTP_USER_AGENT") ‘关键判断语句 
if instr(1,s_agent,"googlebot",1) >0 then 
GetBot="google" 
end if 
if instr(1,s_agent,"msnbot",1) >0 then 
GetBot="MSN" 
end if 
if instr(1,s_agent,"slurp",1) >0 then 
GetBot="Yahoo" 
end if 
if instr(1,s_agent,"baiduspider",1) >0 then 
GetBot="baidu" 
end if 
if instr(1,s_agent,"sohu-search",1) >0 then 
GetBot="Sohu" 
end if 
if instr(1,s_agent,"lycos",1) >0 then 
GetBot="Lycos" 
end if 
if instr(1,s_agent,"robozilla",1) >0 then 
GetBot="Robozilla" 
end if 
end function 
if GetBot="baidu" then 
'给百度定制的内容 
elseif GetBot="google" then 
'给google 定制的内容 
end if 
%>

下面是比较完整的代码需要的朋友也可以参考下。里面还包括了一些客户端信息。

代码如下:


Class SystemInfo_Cls 
Public Browser, version, platform, IsSearch, AlexaToolbar 
Private Sub Class_Initialize() 
Dim Agent, Tmpstr 
IsSearch = False 
If Not IsEmpty(Session("SystemInfo_Cls")) Then 
Tmpstr = Split(Session("SystemInfo_Cls"), "|||") 
Browser = Tmpstr(0) 
version = Tmpstr(1) 
platform = Tmpstr(2) 
AlexaToolbar = Tmpstr(4) 
If Tmpstr(3) = "1" Then 
IsSearch = True 
End If 
Exit Sub 
End If 
Browser = "unknown" 
version = "unknown" 
platform = "unknown" 
Agent = Request.ServerVariables("HTTP_USER_AGENT") 
If InStr(Agent, "Alexa Toolbar") > 0 Then 
AlexaToolbar = "YES" 
Else 
AlexaToolbar = "NO" 
End If 
If Left(Agent, 7) = "Mozilla" Then '有此标识为浏览器 
Agent = Split(Agent, ";") 
If InStr(Agent(1), "MSIE") > 0 Then 
Browser = "Internet Explorer " 
version = Trim(Left(Replace(Agent(1), "MSIE", ""), 6)) 
ElseIf InStr(Agent(4), "Netscape") > 0 Then 
Browser = "Netscape " 
Tmpstr = Split(Agent(4), "/") 
version = Tmpstr(UBound(Tmpstr)) 
ElseIf InStr(Agent(4), "rv:") > 0 Then 
Browser = "Mozilla " 
Tmpstr = Split(Agent(4), ":") 
version = Tmpstr(UBound(Tmpstr)) 
If InStr(version, ")") > 0 Then 
Tmpstr = Split(version, ")") 
version = Tmpstr(0) 
End If 
End If 
If InStr(Agent(2), "NT 5.2") > 0 Then 
platform = "Windows 2003" 
ElseIf InStr(Agent(2), "Windows CE") > 0 Then 
platform = "Windows CE" 
ElseIf InStr(Agent(2), "NT 5.1") > 0 Then 
platform = "Windows XP" 
ElseIf InStr(Agent(2), "NT 4.0") > 0 Then 
platform = "Windows NT" 
ElseIf InStr(Agent(2), "NT 5.0") > 0 Then 
platform = "Windows 2000" 
ElseIf InStr(Agent(2), "NT") > 0 Then 
platform = "Windows NT" 
ElseIf InStr(Agent(2), "9x") > 0 Then 
platform = "Windows ME" 
ElseIf InStr(Agent(2), "98") > 0 Then 
platform = "Windows 98" 
ElseIf InStr(Agent(2), "95") > 0 Then 
platform = "Windows 95" 
ElseIf InStr(Agent(2), "Win32") > 0 Then 
platform = "Win32" 
ElseIf InStr(Agent(2), "Linux") > 0 Then 
platform = "Linux" 
ElseIf InStr(Agent(2), "SunOS") > 0 Then 
platform = "SunOS" 
ElseIf InStr(Agent(2), "Mac") > 0 Then 
platform = "Mac" 
ElseIf UBound(Agent) > 2 Then 
If InStr(Agent(3), "NT 5.1") > 0 Then 
platform = "Windows XP" 
End If 
If InStr(Agent(3), "Linux") > 0 Then 
platform = "Linux" 
End If 
End If 
If InStr(Agent(2), "Windows") > 0 And platform = "unknown" Then 
platform = "Windows" 
End If 
ElseIf Left(Agent, 5) = "Opera" Then '有此标识为浏览器 
Agent = Split(Agent, "/") 
Browser = "Mozilla " 
Tmpstr = Split(Agent(1), " ") 
version = Tmpstr(0) 
If InStr(Agent(1), "NT 5.2") > 0 Then 
platform = "Windows 2003" 
ElseIf InStr(Agent(1), "Windows CE") > 0 Then 
platform = "Windows CE" 
ElseIf InStr(Agent(1), "NT 5.1") > 0 Then 
platform = "Windows XP" 
ElseIf InStr(Agent(1), "NT 4.0") > 0 Then 
platform = "Windows NT" 
ElseIf InStr(Agent(1), "NT 5.0") > 0 Then 
platform = "Windows 2000" 
ElseIf InStr(Agent(1), "NT") > 0 Then 
platform = "Windows NT" 
ElseIf InStr(Agent(1), "9x") > 0 Then 
platform = "Windows ME" 
ElseIf InStr(Agent(1), "98") > 0 Then 
platform = "Windows 98" 
ElseIf InStr(Agent(1), "95") > 0 Then 
platform = "Windows 95" 
ElseIf InStr(Agent(1), "Win32") > 0 Then 
platform = "Win32" 
ElseIf InStr(Agent(1), "Linux") > 0 Then 
platform = "Linux" 
ElseIf InStr(Agent(1), "SunOS") > 0 Then 
platform = "SunOS" 
ElseIf InStr(Agent(1), "Mac") > 0 Then 
platform = "Mac" 
ElseIf UBound(Agent) > 2 Then 
If InStr(Agent(3), "NT 5.1") > 0 Then 
platform = "Windows XP" 
End If 
If InStr(Agent(3), "Linux") > 0 Then 
platform = "Linux" 
End If 
End If 
Else 
'识别搜索引擎 
Dim botlist, i 
botlist = "Google,Isaac,Webdup,SurveyBot,Baiduspider,ia_archiver,P.Arthur,FAST-WebCrawler,Java,Microsoft-ATL-Native,TurnitinBot,WebGather,Sleipnir" 
botlist = Split(botlist, ",") 
For i = 0 To UBound(botlist) 
If InStr(Agent, botlist(i)) > 0 Then 
platform = botlist(i) & "搜索器" 
IsSearch = True 
Exit For 
End If 
Next 
End If 
If IsSearch Then 
Browser = "" 
version = "" 
Session("SystemInfo_Cls") = Browser & "|||" & version & "|||" & platform & "|||1|||" & AlexaToolbar 
Else 
Session("SystemInfo_Cls") = Browser & "|||" & version & "|||" & platform & "|||0|||" & AlexaToolbar 
End If 
End Sub 
End Class


 

标签:asp,搜索引擎,蜘蛛
0
投稿

猜你喜欢

  • 正在研究XMLHTTP如何正确传送大于7F(127)的二进制数据

    2008-09-13 18:41:00
  • SQL Server重温 事务

    2012-08-21 10:48:15
  • 关于mysql与mysqli

    2011-02-23 12:03:00
  • SQL Server保障数据一致性的法宝

    2008-12-26 15:21:00
  • WEB设计经验-来自Microsoft

    2008-05-15 07:30:00
  • MySQL5创建存储过程实例

    2010-06-13 12:49:00
  • String.indexOf 方法介绍

    2013-06-01 20:22:27
  • 菜鸟课堂:详述如何提高MySQL中数据装载效率

    2009-10-23 14:29:00
  • 设计与用户体验

    2009-05-06 13:36:00
  • asp 采集程序常用函数分析

    2011-03-16 11:03:00
  • discuz 2.0整合asp系统,用户添加函数

    2011-04-02 11:08:00
  • 最简便的备份MySQL数据库的方法

    2008-12-25 13:16:00
  • 使用游标进行PHP SQLSRV查询的方法与注意事项

    2023-05-22 10:51:10
  • 如何让WML页面自己更新?

    2008-05-21 13:35:00
  • 斜角滑动门导航条 DIV+CSS

    2008-07-19 15:45:00
  • 精致的web设计

    2009-12-04 19:07:00
  • FrontPage服务器扩展

    2008-03-05 13:05:00
  • 最简短的拖动对象js代码实例

    2007-10-09 13:33:00
  • css+JavaScript实现PDF、ZIP、DOC链接的标注

    2007-05-11 17:03:00
  • 20个优秀网站助你征服CSS[译]

    2008-09-21 13:21:00
  • asp之家 网络编程 m.aspxhome.com