Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP获取Google搜索结果的数量?_Php - Fatal编程技术网

如何使用PHP获取Google搜索结果的数量?

如何使用PHP获取Google搜索结果的数量?,php,Php,我正在努力寻找一种方法来获得谷歌搜索结果使用PHP的数量?我搜索过谷歌和stackoverflow,但没有找到任何合适的 我想知道如何使用PHP实现这一点。不使用API时: $content = file_get_contents('https://www.google.com/search?q=test'); preg_match('/<div class="sd" id="resultStats">.*?([0-9\.\,]+).*?<\/div>/', $conte

我正在努力寻找一种方法来获得谷歌搜索结果使用PHP的数量?我搜索过谷歌和stackoverflow,但没有找到任何合适的

我想知道如何使用PHP实现这一点。

不使用API时:

$content = file_get_contents('https://www.google.com/search?q=test');
preg_match('/<div class="sd" id="resultStats">.*?([0-9\.\,]+).*?<\/div>/', $content, $matches);

var_dump($matches[1]);
$content=file\u get\u contents('https://www.google.com/search?q=test');
预匹配(“/.*”([0-9\.\,]+).*?/”,$content,$matches);
var_dump($matches[1]);

尽管我建议不要使用这种(自动)查询方式。

您可以解析谷歌搜索页面。 在返回页面中,有一些谷歌搜索结果。 比如,, 当我们在google搜索框中搜索
stackoverflow
时,这些文本将出现在google搜索框下:
大约34800000个结果(0.79秒)

请检查。实际上,Google Web Search API在2010年11月1日正式被弃用。实际上,[Google Web Search API在2010年11月1日正式被弃用]()。所以Brijesh Khatri提供的方法可能会失败。这种方法是最好且简单的。