我使用下面的代码来获取搜索结果。当我在google中插入字符串时,我得到了一个搜索结果,但当我试图通过代码获取结果时,它什么也没有返回。有人能解释一下为什么代码不工作吗?如果我输入其他搜索词,它会返回结果
<?php
$string="make them see things from your view";
$request = trim("http://ajax.googleapis.com/ajax/services/search/web");
$referrer = trim("http://localhost/");
$version = "1.0";
$getargs = '?v='. $version .'&rsz=small&q="'. urlencode($string).'"' ;
// Get the curl session object
$session = curl_init($request . $getargs);
// Set the GET options.
curl_setopt($session, CURLOPT_HTTPGET, true);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_REFERER, $referrer);
//var_dump $response;
$response=null;
// Do the POST and then close the session
$response = curl_exec($session);
curl_close($session);
var_dump ($response);
// Get HTTP Status code from the response
$status_code = array();
preg_match('/\d\d\d/', $response, $status_code);
print_r($status_code);
?>
发布于 2011-02-09 15:10:48
您的代码很好。它进行API调用并获得响应。
如果你进行不同的搜索,比如“数码相机”,结果就是响应的一部分。
为什么API返回的结果不同于Google的几十个数据中心返回的结果,这是一个只有Google或Google文档可以回答的问题。
https://stackoverflow.com/questions/4942042
复制相似问题