日期:2015/6/28来源: IT猫扑网
搜索引擎的蜘蛛访问网站是通过远程抓取页面来进行的,我们不能使用JS代码来取得蜘蛛的Agent信息,但是我们可以通过image标签,这样我们就可以得到蜘蛛的agent资料了,通过对agent资料的分析,就可以确定蜘蛛的种类、性别等因素,我们在通过数据库或者文本来记录就可以进行统计了。
数据库结构:
以下为引用的内容: #
# 表的结构 `naps_stats_bot` #
CREATE TABLE `naps_stats_bot` ( # INSERT INTO `naps_stats_bot` VALUES (1, 'Googlebot', 'Googlebot/2.X (+https://www.googlebot.com/bot.html)', 'googlebot', 0, '0000-00-00 00:00:00', ''); |
php程序:
以下为引用的内容: <?php/*************************************************************************** * NAPS -- Network Article Publish System * ---------------------------------------------- * bot.php * ------------------- * begin : 2004-08-15 * copyright : (C) 2004 week9 * email : wapshow@gmail.com * homepage : https://www.week9.com * https://www.wapshow.com * ***************************************************************************/ /*************************************************************************** * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License. * ***************************************************************************/ /*************************************************************************** * * NAPS产品是自由软件。你可以且必须根据《GNU GPL-GNU通用公共许可证》的相关规定 * 复制、修改及分发NAPS产品。任何以NAPS产品为基础的衍生发行版未必须经过飘飘的授权。 * ***************************************************************************/ error_reporting(E_ALL & ~E_NOTICE); function get_naps_bot() { $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); if (strpos($useragent, 'googlebot') !== false){ return 'Googlebot'; } if (strpos($useragent, 'msnbot') !== false){ return 'MSNbot'; } if (strpos($useragent, 'slurp') !== false){ return 'Yahoobot'; } if (strpos($useragent, 'baiduspider') !== false){ return 'Baiduspider'; } if (strpos($useragent, 'sohu-search') !== false){ return 'Sohubot'; } if (strpos($useragent, 'lycos') !== false){ return 'Lycos'; } if (strpos($useragent, 'robozilla') !== false){ return 'Robozilla'; } return false; } $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']); //添加蜘蛛的抓取记录 $searchbot = get_naps_bot(); if ($searchbot) { $DB_naps->query(" 相关文章 相关下载 网友评论 |