gpt4 book ai didi

php - 如何获取 Google 机器人上次访问该页面的时间?

转载 作者:可可西里 更新时间:2023-11-01 13:51:08 26 4
gpt4 key购买 nike

我有以下函数来获取 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 并打印它,即:2011 年 10 月 8 日 14:03:12 GMT .

怎么做?

最佳答案

改变这一行:

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 />";

关于php - 如何获取 Google 机器人上次访问该页面的时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7765858/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com