Advertisement
niammuddin

google bing yahoo jevuska

Jul 19th, 2014
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.80 KB | None | 0 0
  1. <?php
  2. define('BING_API_KEY', '');
  3. define('YAHOO_API_KEY', '');
  4. define('GOOGLE_API_KEY', '');
  5.  
  6. function pete_curl_get($url, $params){$post_params = array();
  7. foreach ($params as $key => &$val) {
  8. if (is_array($val)) $val = implode(',', $val);
  9. $post_params[] = $key.'='.urlencode($val);
  10. }
  11. $post_string = implode('&', $post_params);
  12. $fullurl = $url."?".$post_string;
  13. $ch = curl_init();curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);curl_setopt($ch, CURLOPT_URL, $fullurl);
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  16. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040608'); //kamu bisa pake user agent yang lain, lihat listnya di sini www.user-agents.org
  17. $result = curl_exec($ch);curl_close($ch);
  18. return $result;
  19. }
  20. function perform_bing_web_search($termstring){$searchurl = 'http://api.bing.net/json.aspx?';
  21. $searchurl .= 'AppId='.'ABCDEFG'; //ganti ABCDEFG dengan kode api BING http://www.bing.com/developers/appids.aspx
  22. $searchurl .= '&Query='.urlencode($termstring);
  23. $searchurl .= '&Sources=Web';
  24. $searchurl .= '&Web.Count=10'; //jumlah list situs yang dihasilkan
  25. $searchurl .= '&Web.Offset=0';
  26. $searchurl .= '&Web.Options=DisableHostCollapsing+DisableQueryAlterations';
  27. $searchurl .= '&JsonType=raw';
  28. $response = pete_curl_get($searchurl, array());
  29. $responseobject = json_decode($response, true);if ($responseobject['SearchResponse']['Web']['Total']==0)return array();
  30. $allresponseresults = $responseobject['SearchResponse']['Web']['Results'];
  31. $result = array();
  32. foreach ($allresponseresults as $responseresult){$result[] = array('url' => $responseresult['Url'],'title' => $responseresult['Title'],'abstract' => $responseresult['Description'],);
  33. }return $result;
  34. }
  35. function perform_google_web_search($termstring)
  36. {
  37. $start = 0;
  38. $result = array();
  39. while ($start<10) //kamu bisa ganti angka "10" untuk jumlah list  yang ditampilkan
  40. {
  41. $searchurl = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0';
  42. $searchurl .= '&key='.'ABCDEFG'; //ganti ABCDEFG dengan kode api Google http://code.google.com/apis/ajaxsearch/signup.html
  43. $searchurl .= '&start='.$start;
  44. $searchurl .= '&rsz=large'; //kamu bisa pake "small" untuk menampilkan hanya 4 (maksimal) pencarian
  45. $searchurl .= '&filter=0'; //kamu bisa ganti "filter=1" untuk mem-filter hasil pencarian
  46. $searchurl .= '&q='.urlencode($termstring);
  47. $response = pete_curl_get($searchurl, array());
  48. $responseobject = json_decode($response, true);
  49. if (count($responseobject['responseData']['results'])==0)
  50. break;
  51. $allresponseresults = $responseobject['responseData']['results'];
  52. foreach ($allresponseresults as $responseresult)
  53. {
  54. $result[] = array(
  55. 'url' => $responseresult['url'],
  56. 'title' => $responseresult['title'],
  57. 'abstract' => $responseresult['content'],
  58. );
  59. }
  60. $start += 8;
  61. }
  62. return $result;
  63. }
  64.  
  65. function perform_boss_web_search($termstring)
  66. {
  67. $searchurl = 'http://boss.yahooapis.com/ysearch/web/v1/';
  68. $searchurl .= urlencode($termstring);
  69. $searchparams = array(
  70. 'appid' => 'ABCDEFG', //ganti ABCDEFG dengan kode api Yahoo Boss https://developer.apps.yahoo.com/projects/projects
  71. 'format' => 'json',
  72. 'count' => '10',
  73. );
  74. $response = pete_curl_get($searchurl, $searchparams);
  75. $responseobject = json_decode($response, true);
  76. error_log(print_r($responseobject, true));
  77. if ($responseobject['ysearchresponse']['totalhits']==0)
  78. return array();
  79. $allresponseresults = $responseobject['ysearchresponse']['resultset_web'];
  80. $result = array();
  81. foreach ($allresponseresults as $responseresult)
  82. {
  83. $result[] = array(
  84. 'url' => $responseresult['url'],
  85. 'title' => $responseresult['title'],
  86. 'abstract' => $responseresult['abstract'],
  87. );
  88. }
  89. return $result;
  90. }if (isset($_REQUEST['s'])) {
  91. $termstring = urldecode($_REQUEST['s']);
  92. } else {
  93. $termstring = '';}
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement