如何使用谷歌API模拟真正的浏览器进行搜索


How to simulate a true browser with Google API for search?

目前我正在使用类似这段代码的东西:

$tracks[0] = 'insert popular random song here';
$query = urlencode($tracks[0]." download 4shared");
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".$query;
$json = json_decode(file_get_contents($url));
echo $json->responseData->results[0]->url."<br/>";
echo $json->responseData->results[1]->url."<br/>";
echo $json->responseData->results[2]->url;

当我从浏览器在谷歌上搜索"chop suey download 4shared"时,它会返回一些 4shared 下载页面,但是当我使用上面列出的方法时,它会从 soundcloud 返回一些随机链接并从 4shared 搜索,这对我的目的完全没用。我在Firefox,Chrome和Chrome隐身版上尝试过

如何使用谷歌API搜索获得与浏览器相同的结果?

编辑

通过更改其查询部分解决了它:

$query = "site:4shared.com+".str_replace(' ', '+', $track[0]);

你没有。

从浏览器搜索中获得不同的结果,因为Google通常知道您是谁,并定制其搜索结果以更适合。如果您从其他人的浏览器进行搜索,您将获得不同的结果。

当您通过API在我假设的服务器上运行查询时,Google没有您的个人资料,或者可能没有任何个人资料,并基于此返回结果集。

这被称为过滤气泡,一旦你知道自己在一个里面,可能会有点愤怒。