【问题标题】:How to get Google Indexed pages count via PHP如何通过 PHP 获取 Google 索引页面计数
【发布时间】:2015-03-20 18:02:45
【问题描述】:

您好,我正在尝试创建一个脚本,该脚本应该从 Google 检索所有索引页面的计数。只有总页数(来自 site:$domain 的结果)

我找到了这个脚本:

function getGoogleCount($domain) {
$content = file_get_contents('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&filter=0&q=site:' . urlencode($domain));
$data = json_decode($content);
return intval($data->responseData->cursor->estimatedResultCount);
}

但是这个 API 是旧的并且给出了不同的计数,那么有没有其他方法来获取索引页面计数?

谢谢

【问题讨论】:

  • 您可以使用Google's webmaster tools,它可以为您提供他们已在您的网站上编入索引的许多页面。您可以更进一步,向 Google 提供站点地图 XML 文件,以帮助确保 googlebot 知道要索引的内容。
  • 如果您尝试获取有关您控制的站点的数据,那么@Crackertastic 是正确的。如果您正在尝试创建一项服务,允许您或其他人获取有关第三方网站的数据,那么该 API 可能是最好的方法。 estimatedResultCount 是四舍五入的,但它们不会提供更具体的数据。你说它“给出不同的计数”。你拿它比什么?
  • 是的,我正在尝试为第三方网站提供服务。实际 api 的问题是,例如,如果我搜索一个 url 给我 estimatedResultCount:200;,但如果我在 google.com/search?q=domain.com 上搜索,实际结果是 1700...

标签: php json google-api


【解决方案1】:

试试这个:

<?php
function getpageindexed($name){
$weburl="http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:".$name."&filter=0";
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $weburl);
curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$json = curl_exec($ch);
curl_close($ch);
$data=json_decode($json,true);
if($data['responseStatus']==200)
return $data['responseData']['cursor']['resultCount'];
else
return false;
}

$name="domainname.com"; //your domain name
echo getpageindexed($name); //get indexed page
?>

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-13
  • 2011-08-27
  • 2020-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多