正文:
最近我在研究搜狗的收录方法,想要找到搜狗蜘蛛的渠道(不过目前已经没有了)。为了方便统计搜狗蜘蛛爬取的 URL
,我写了一段代码。
起初,我以为这个统计搜狗蜘蛛的工作很简单,但没想到搜狗的标识符并不是“sougouspider
”。我尝试了几种不同的写法,但都没有成功。
最后,在“老虎域名”的提示下,我直接将“sougou
”作为统计蜘蛛的标识,这样才成功了。
在众多尝试中,我不断寻找搜狗的标识,经过千百次的搜索,突然回头一看,搜狗的标识就在灯火阑珊处。
<?php
function get_naps_bot()
{
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($useragent, 'sogou') !== false){
return 'sogouspider';
}
return false;
}
function nowtime(){
$date=gmdate("Y-n-j H:i:s",time()+8*3600);
return $date;
}
$searchbot = get_naps_bot();
if ($searchbot) {
$tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
$url=$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$file="spiderlogs.txt";
$time=nowtime();
$data=fopen($file,"a");
fwrite($data,"Time:$time robot:$searchbot URL:$url\n");
fclose($data);
}
?>
在泛目录的 index.php
/404
.php/sitemapphp
的等相关蜘蛛会访问到的文件中插入:
include'spider.php';
转载请注明:汇站网 » 统计搜狗蜘蛛的PHP代码,方便自己使用