我需要一个PHP Google搜索功能,所以我尝试了很多我在Google上找到的功能,但几乎所有功能都有同样的问题,即他们直接从Google主网址获取结果,而不是来自API网址,这导致一段时间后错误,因为Google检测到来自PHP服务器的访问并拒绝任何进一步的请求。
因此,我将Google搜索功能从Google API网址中获取结果,并且完全按照您在此处#API_URL的效果完成,直到我需要减少结果购买之前添加 intitle:已搜索的关键字,现在API网址根本没有返回任何结果#API_URL。
我的问题很简单,如何使用此查询在Google API网址中获得结果 intitle:maleficent + 2014 + site:www.anakbnet.com/video/file.php?f = 这样我可以使用PHP从中获取结果吗?
答案 0 :(得分:1)
您从“Google API”调用中获取的数据是json编码数据,因此您应该尝试以下内容: -
/* define a constant for ease */
define('BR','<br />');
$data='{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.anakbnet.com/video/file.php?f\u003d1452","url":"http://www.anakbnet.com/video/file.php%3Ff%3D1452","visibleUrl":"www.anakbnet.com","cacheUrl":"http://www.google.com/search?q\u003dcache:9-JgVUvjnGYJ:www.anakbnet.com","title":"مشاهدة فيلم Alexander and the Terrible اون لاين مباشرة بدون تحميل \u003cb\u003e...\u003c/b\u003e","titleNoFormatting":"مشاهدة فيلم Alexander and the Terrible اون لاين مباشرة بدون تحميل ...","content":"29 كانون الثاني (يناير) 2015 \u003cb\u003e...\u003c/b\u003e مشاهدة فيلم \u003cb\u003eMaleficent 2014\u003c/b\u003e DVD HD مترجم اون لاين مباشرة بدون تحميل اكشن ,مغامرة \n,عائلي .. مشاهدة افلام اجنبية مترجمة اونلاين كاملة. (مشاهدة: 491,605 )."}],"cursor":{"resultCount":"1","pages":[{"start":"0","label":1}],
"estimatedResultCount":"1",
"currentPageIndex":0,
"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d0\u0026hl\u003den-GB\u0026q\u003dmaleficent+2014+site:www.anakbnet.com/video/file.php?f%3D",
"searchResultTime":"0.09"}},
"responseDetails": null,
"responseStatus": 200}';
$json=json_decode( $data, true );
$res=(object)$json['responseData']['results'][0];
/* two items extracted from data - use same methodology to get other items */
echo $res->unescapedUrl;
echo $res->cacheUrl;
echo '<pre>';
foreach( $json as $key => $param ){
echo $key.BR;
if( is_array( $param )) $param=(object)$param;
print_r( $param );
}
echo '</pre>';
希望你可以找到你想要的东西?!