Advertisement
AbdulMuttaqin

adwords scraper

Oct 27th, 2019
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. function GRKG_ajax() {
  2.         global $wpdb; // this is how you get access to the database
  3.  
  4.         if(isset($_POST['getAjaxWPTerm'])) {
  5.             $term = urlencode($_POST['getAjaxWPTerm']);
  6.             $getLimit = $_POST['getAjaxWPMax'];
  7.             $getLocale = $_POST['getAjaxWPLocale'];
  8.            
  9.             $getLocale = str_replace("_", "-", $getLocale);
  10.  
  11.             $get_useragent = $_SERVER['HTTP_USER_AGENT'];
  12.  
  13.             $url = 'https://api.bing.com/osjson.aspx?query='.$term.'&setmkt='.$getLocale;
  14.             $ch  = curl_init();
  15.             curl_setopt($ch, CURLOPT_URL, $url);
  16.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  17.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  18.             curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  19.             curl_setopt($ch, CURLOPT_USERAGENT, $get_useragent);
  20.             curl_setopt($ch, CURLOPT_REFERER, "https://google.com");
  21.             $result = curl_exec($ch);
  22.             curl_close($ch);
  23.  
  24.             $resultInArray = json_decode($result, true);
  25.  
  26.             //
  27.             $resultCount = count($resultInArray[1]);
  28.  
  29.             for ( $i = 1; $i < $resultCount; $i++ ) {
  30.                 echo $resultInArray[1][$i].', ';
  31.                
  32.                 if ( $i == $getLimit)
  33.                     break;
  34.             }
  35.         }
  36.        
  37.         wp_die();
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement