欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net(c#)捕捉搜索引擎蜘蛛和机器人

程序员文章站 2023-03-13 19:36:51
下面是访问日志文件2008-8-13 14:43:22 mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; .net cl...
下面是访问日志文件
2008-8-13 14:43:22

mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; .net clr 2.0.50727; .net clr 1.1.4322)



2008-8-13 14:43:27

mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; .net clr 2.0.50727; .net clr 1.1.4322)



2008-8-13 14:44:18

mozilla/5.0 (compatible; yahoo! slurp; http://help.yahoo.com/help/us/ysearch/slurp)



2008-8-13 14:44:26

mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; sv1; maxthon; qqdownload 1.7; .net clr 1.1.4322; .net clr 2.0.50727; .net clr 3.0.04506.648; .net clr 3.5.21022)



2008-8-13 14:45:17

mozilla/5.0 (compatible; yahoo! slurp; http://help.yahoo.com/help/us/ysearch/slurp)

打开这个文件,这个文件用于记录访问搜索吧的正常访客或者机器人蜘蛛,从中提取的蜘蛛有: mozilla/5.0 (compatible; googlebot/2.1; +http://www.google.com/bot.html)

gigabot/3.0 (http://www.gigablast.com/spider.html)

mozilla/5.0 (compatible; yahoo! slurp; http://help.yahoo.com/help/us/ysearch/slurp)

mozilla/5.0 (compatible; yodaobot/1.0; http://www.yodao.com/help/webmaster/spider/; )

sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)

msnbot/1.1 (+http://search.msn.com/msnbot.htm)

baiduspider+(+http://www.baidu.com/search/spider.htm)

代码也十分的简单:
复制代码 代码如下:

string agent = system.web.httpcontext.current.request.servervariables["http_user_agent"];
if (agent == null)
{
response.write("other");
}
else
{
response.write(agent);
}

你可以自己用这个代码试下,发现会输出类似: mozilla/4.0 (compatible; msie 7.0; windows nt 5.1; tencenttraveler 4.0; .net clr 2.0.50727; .net clr 1.1.4322)
结合这个你就可以写一个蜘蛛访问记录了,如何判断正常用户或者蜘蛛?可以粗略的这样来判断:通过判断用户的访问来源页面,比如从jb51.net/index.htm这个文件点进show.asp?id=11那么他的来源页面我们知道就是jb51.net/index.htm,那么粗略判断他就是正常客户。而蜘蛛的来源则不是,把这部分不是的记录下来,再从中选择。可以结合数据库进行记录。