使用谷歌自定义搜索来查找索引网址的数量

时间:2013-07-31 03:03:50

标签: php google-api google-custom-search

我正在寻找一种很好的方法来查找我的网站中有多少页面在Google中编入索引。我一直在看谷歌自定义搜索API。以下是他们在示例文档中提供的代码。

require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_CustomsearchService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName('Internet Report Card');
$client->setDeveloperKey('XXXXXX MY KEY');
$search = new Google_CustomsearchService($client);
$result = $search->cse->listCse('site:mysite.com', array(
    'cref' => 'http://www.google.com/???????????',                                                                            
));
print "<pre>" . print_r($result, true) . "</pre>";

我似乎无法弄清楚我的cref应该是什么,或者代码应该是什么以便提取正确的信息。

我在很多网站上看到了以下网址代码

https://www.googleapis.com/customsearch/v1?key={{Removed API Key}}&q=site:' . $domain

我可能错了,但我相信这是旧api的代码。

2 个答案:

答案 0 :(得分:-1)

您可以使用ajax搜索API来获取索引页面的总数:

http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=YOURSITE.COM

答案 1 :(得分:-2)

这就是Google网站管理员工具的用途。您可以在此处阅读更多内容:https://support.google.com/webmasters/answer/2642366?hl=en