记录搜索引擎蜘蛛爬行信息

  对于wordpress来说,记录搜索引擎爬行记录的插件应该有很多。但是我们也知道,插件过多势必会影响页面加载速度,所以我给大家提供一段代码,来记录搜索引擎的爬行信息,这段代码很早以前就有人在网上放出来了。

  监视搜索引擎蜘蛛爬行记录的代码:文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

<?php文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

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, 'sosospider') !== false){
    return 'sosospider';
  }
 
  if (strpos($useragent, 'sogou spider') !== false){
    return 'sogou spider';
  }
 
  if (strpos($useragent, 'YoudaoBot') !== false){
    return 'YoudaoBot';
  }文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

  return false;
}
function nowtime(){
  $date=date("Y-m-d.G:i:s");文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

  return $date;
}文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

$searchbot = get_naps_bot();文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

if ($searchbot) {
  $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
  $url=$_SERVER['HTTP_REFERER'];
  $file="robotslogs.txt";
  $time=nowtime();
  $data=fopen($file,"a");
  fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n");
  fclose($data);
}
?>文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

  这段代码主要利用各大搜索引擎蜘蛛爬行程序都有自己的标识符,google的标识符为:googlebot,百度的标识符为:baiduspider,它们可以通过查询_SERVER变量中的HTTP_USER_AGENT参数来获取,再结合HTTP_REFERER记录下的URL的来源,最后用nowtime()函数来获取当前系统时间,最后将是那个面得到的参数写入robotslogs.txt文档中。文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

  新建一个php文件(名字自定),例如spider.php。最后上传到wordpress当前正在使用主题的目录中,最后在主题的foot.php中调用spider.php文件。文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

<?php include('spider.php') ?>文章源自堕落的鱼-https://www.duoluodeyu.com/324.html

通过一段时间的运行,你就可以通过http://www.youdomain.com/robotslogs.txt来查看搜索引擎蜘蛛的访问记录了。

 最后更新:2011-5-6
    • Hello Beautiful
      Hello Beautiful 0

      记录不了访问页面就不爽了。。

    匿名

    发表评论

    匿名网友
    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
    确定

    拖动滑块以完成验证