如何使用api获取所有Google搜索结果 [英] how to get ALL google search results using api

查看:498
本文介绍了如何使用api获取所有Google搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取Google搜索结果以进行查询.但是使用这样的东西

I need to get google search results for query. But using something like this

$query = 'Nikita Platonenko';
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".urlencode($query);
$body = file_get_contents($url);
$json = json_decode($body);
var_dump($json)

我只得到4条结果,我已经读过有关Google Ajax搜索的信息,但听不懂.请告知如何获得所有结果,或仅获得前100个结果?

i get only 4 results, I've already read about google ajax search but couldn't understand it. Please advise how to get all resulsts, or just first 100 results?

推荐答案

<?php
$query = 'Nikita%20Platonenko';
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".$query;

$body = file_get_contents($url);
$json = json_decode($body);

for($x=0;$x<count($json->responseData->results);$x++){

echo "<b>Result ".($x+1)."</b>";
echo "<br>URL: ";
echo $json->responseData->results[$x]->url;
echo "<br>VisibleURL: ";
echo $json->responseData->results[$x]->visibleUrl;
echo "<br>Title: ";
echo $json->responseData->results[$x]->title;
echo "<br>Content: ";
echo $json->responseData->results[$x]->content;
echo "<br><br>";

}

?>

由于AJAX Api现在已贬值,因此您可以使用第三方服务,例如 SerpApi 来获取Google结果.他们有一个 GitHub 存储库,并且应该易于集成:

As the AJAX Api is now depreciated, you can use a third party service like SerpApi to get Google results. They have a GitHub repository, and it should be easy to integrate:

$query = [
    "q" => "Coffee",
    "google_domain" => "google.com",
];

$serp = new GoogleSearchResults();
$json_results = $serp.json($query);

这篇关于如何使用api获取所有Google搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆