【问题标题】:How can I get the time the Google bot last accessed the page?如何获取 Google 机器人上次访问该页面的时间?
【发布时间】:2011-12-07 15:04:44
【问题描述】:

我有以下函数来获取googlebot的最后访问日期:

//get googlebot last access
function googlebot_lastaccess($domain_name)
{
    $request = 'http://webcache.googleusercontent.com/search?hl=en&q=cache:'.$domain_name.'&btnG=Google+Search&meta=';
    $data = getPageData($request);
    $spl=explode("as it appeared on",$data);
   //echo "<pre>".$spl[0]."</pre>";
    $spl2=explode(".<br>",$spl[1]);
    $value=trim($spl2[0]);
   //echo "<pre>".$spl2[0]."</pre>";
    if(strlen($value)==0)
    {
        return(0);
    }
    else
    {
        return($value);
    }      
} 

echo "Googlebot last access = ".googlebot_lastaccess($domain_name)."<br />"; 

function getPageData($url) {
 if(function_exists('curl_init')) {
 $ch = curl_init($url); // initialize curl with given url
 curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // add useragent
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
 if((ini_get('open_basedir') == '') && (ini_get('safe_mode') == 'Off')) {
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
 }
 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); // max. seconds to execute
 curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
 return @curl_exec($ch);
 }
 else {
 return @file_get_contents($url);
 }
}

但是这个脚本会打印出我屏幕上整个页面的快照,即。整个页面缓存在谷歌中,但我只想捕获单词as it appeared on 之后的日期时间并打印出来,即:8 Oct 2011 14:03:12 GMT

怎么做?

【问题讨论】:

  • 我想知道谷歌是否有任何API来获取价值......

标签: php googlebot


【解决方案1】:

改变这一行:

echo "Googlebot last access = ".googlebot_lastaccess($domain_name)."<br />";

用这个:

$content = googlebot_lastaccess($domain_name);
$date = substr($content , 0, strpos($content, 'GMT') + strlen('GMT'));
echo "Googlebot last access = ".$date."<br />"; 

【讨论】:

  • mmm 问题 google ban me 我们的系统检测到来自您的计算机的来自网络的异常流量。任何软解决方案?
  • @grigione 通常他们会禁止你一段时间。不要滥用谷歌做一个太请求。他们的使用许可禁止这样做。
【解决方案2】:

当您可以在您的网站上检测到 Googlebot 以及它位于哪些页面时,为什么要向 Google 询问它上次访问您网站的时间?它还允许您通过简单的数据库写入功能跟踪 Googlebot 的去向。

查看堆栈溢出问题how to detect search engine bots with php?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-18
    • 2017-01-27
    • 2018-07-20
    • 2021-05-22
    • 2017-01-02
    • 2012-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多