如何通过PHP获取谷歌索引页数 [英] How to get Google Indexed pages count via PHP
问题描述
您好我正在尝试创建一个脚本,该脚本应该可以检索来自Google的所有索引页面的计数。
我只找到总页数(网站结果:$ domain) $ p> 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是旧的并给出了不同的计数,所以有其他方法获得索引页数?
谢谢 解决方案
试试这个:
<?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
返回false;
}
$ name =domainname.com; //你的域名
echo getpageindexed($ name); //获得索引页面
?>
Hello I am trying to create a script that should retrieve a count with all indexed pages from Google. Only the count of total pages (the results from site:$domain)
I found this script:
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);
}
But this API is old and gives different count, so is any other way to get the indexed pages count?
Thanks
Try This:
<?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
?>
这篇关于如何通过PHP获取谷歌索引页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!