我需要在谷歌中找到特定域名的索引页面数量,我们如何通过PHP脚本实现这一点?
所以,
foreach ($allresponseresults as $responseresult)
{
$result[] = array(
'url' => $responseresult['url'],
'title' => $responseresult['title'],
'abstract' => $responseresult['content'],
);
}
Run Code Online (Sandbox Code Playgroud)
我为估计的结果数添加了什么?我该怎么做?我知道它是(estimatedResultCount),但我如何添加?我用这样的方式调用标题:$ result ['title']所以如何获取数字以及如何打印数字?
谢谢 :)
Bli*_*ixt 15
我认为谷歌使用他们的RESTful Search API会更好.有关示例调用,请参阅此URL:
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:stackoverflow.com&filter=0
(你对estimatedResultCount价值感兴趣)
在PHP中,您可以使用它file_get_contents来获取数据并json_decode进行解析.
你可以在这里找到文档:
警告:以下代码没有对响应进行任何类型的错误检查!
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);
}
echo getGoogleCount('stackoverflow.com');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6733 次 |
| 最近记录: |