Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php记录蜘蛛爬行历史的实现代码

php记录蜘蛛爬行历史的实现代码

发布时间:2016-12-24   编辑:www.jquerycn.cn
本文介绍下,用php实现的记录蜘蛛爬行历史的一段代码,用于分析蜘蛛对网站的爬行记录还是不错的,对研究seo也有好处,有需要的朋友参考下吧。

PHP记录蜘蛛爬行历史的代码,如下:

<? function 
//记录蜘蛛爬行记录,判断来自哪种搜索引擎
get_naps_bot()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);

if (strpos($useragent, 'googlebot') !== false){
return 'Google';
}

if (strpos($useragent, 'baiduspider') !== false){
return 'Baidu';
}
if (strpos($useragent, 'msnbot') !== false){
return 'Bing';
}

if (strpos($useragent, 'slurp') !== false){
return 'Yahoo';
}

if (strpos($useragent, 'sosospider') !== false){
return 'Soso';
}

if (strpos($useragent, 'sogou spider') !== false){
return 'Sogou';
}

if (strpos($useragent, 'yodaobot') !== false){
return 'Yodao';
}
return false;
}

function nowtime(){
$date=date("Y-m-d.G:i:s");
return $date;
}

$searchbot = get_naps_bot();

//保存爬行记录
if ($searchbot) {
   $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
   $url=$_SERVER['HTTP_REFERER'];
   $file="robotlog.txt";
   $time=nowtime();
   $data=fopen($file,"a");
   fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n");
    fclose($data);
}
?>

您可能感兴趣的文章:
php记录蜘蛛爬行历史的实现代码
搜索引擎蜘蛛爬行统计分析
php获取各搜索蜘蛛爬行记录的代码
php 抓取蜘蛛爬虫痕迹的代码分享
GOOGLE 工作原理分析
分析apache日志中蜘蛛爬行记录数量的shell脚本(图文)
怎么让百度快速收录新网站
零基础python爬虫需要多久
php记录搜索引擎关键词的代码示例
php写的关于静态页面的蜘蛛爬行记录的代码

[关闭]