Google API URL不返回结果



我需要一个PHP谷歌搜索功能,所以我尝试了在谷歌找到的许多功能,但几乎所有功能都有相同的问题,即它们直接从谷歌主URL而不是API URL获取结果,这会导致一段时间后出现错误,因为谷歌检测到访问来自PHP服务器,并拒绝任何进一步的请求。

因此,我让我的谷歌搜索功能从谷歌API URL中获取结果,正如你在这里看到的那样,这非常有效#API_URL,直到我需要减少结果购买,在搜索关键字之前添加标题:,现在API URL根本不返回结果,就像你在这里所看到的那样#API_URL。

我的问题很简单,如何使用以下查询在Google API URL中获得结果intitle:moleficent+2014+site:www.anakbnet.com/video/file.php?f=以便我可以使用PHP从中获取结果?

您从‘Google API’调用返回的数据是json编码的数据,因此您应该尝试以下方法:-

    /* define a constant for ease */
    define('BR','<br />');

    $data='{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.anakbnet.com/video/file.php?fu003d1452","url":"http://www.anakbnet.com/video/file.php%3Ff%3D1452","visibleUrl":"www.anakbnet.com","cacheUrl":"http://www.google.com/search?qu003dcache:9-JgVUvjnGYJ:www.anakbnet.com","title":"مشاهدة فيلم Alexander and the Terrible اون لاين مباشرة بدون تحميل u003cbu003e...u003c/bu003e","titleNoFormatting":"مشاهدة فيلم Alexander and the Terrible اون لاين مباشرة بدون تحميل ...","content":"29 كانون الثاني (يناير) 2015 u003cbu003e...u003c/bu003e مشاهدة فيلم u003cbu003eMaleficent 2014u003c/bu003e DVD HD مترجم اون لاين مباشرة بدون تحميل اكشن ,مغامرة n,عائلي .. مشاهدة افلام اجنبية مترجمة اونلاين كاملة. (مشاهدة: 491,605 )."}],"cursor":{"resultCount":"1","pages":[{"start":"0","label":1}],
     "estimatedResultCount":"1",
     "currentPageIndex":0,
     "moreResultsUrl":"http://www.google.com/search?oeu003dutf8u0026ieu003dutf8u0026sourceu003dudsu0026startu003d0u0026hlu003den-GBu0026qu003dmaleficent+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>';

希望你能从中找到你想要的?!

最新更新