Cara Grab Google Trend di Negara Tertentu


Kode di bawah menggunakan 'p1' sebagai country code amerika.
Cara lihat country code lain, buka link ini http://www.google.com/trends/hottrends

Pilih negaranya dari dropdown, contoh Brazil, maka URL di browser akan jadi



 Maka kode Brazil = p18

Contoh kode negara lain :
- Colombia = p32
- India = p3

PHP Code:

<?php

$keyword 
my_get_google_hot_trend('p1');
echo 
'<pre>'; print_r($keyword['data']);
echo 
'</pre>';
//////////////
function xrvel_curl($url) {
    
$ch curl_init();
    
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    
curl_setopt($chCURLOPT_AUTOREFERERtrue);
    
curl_setopt($chCURLOPT_HEADERfalse);
    @
curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    @
curl_setopt($chCURLOPT_MAXREDIRS2);
    
curl_setopt($chCURLOPT_USERAGENT'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6');
    
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    
curl_setopt($chCURLOPT_COOKIEJARdirname(__FILE__).'/cookie.txt');
    
curl_setopt($chCURLOPT_COOKIEFILEdirname(__FILE__).'/cookie.txt');
    
curl_setopt($chCURLOPT_TIMEOUT30);
    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_REFERER$url);
    
$res trim(curl_exec($ch));
    
curl_close($ch);
    unset(
$ch);
    return 
$res;
}

function 
my_get_google_hot_trend($country_code) {
    
$result = array(
        
'data' => array(),
        
'error' => ''
    
);

    
$res xrvel_curl('http://www.google.com/trends/hottrends/widget?pn='.$country_code.'&tn=10&h=413');

    if (
$res == '') {
        
$result['error'] = 'Failed. Empty response.';
        return 
$result;
    }

    if (!
preg_match_all("/\<span class='widget-title-in-list'\>(.*)\<\/span\>\<\/span\>\<span class='widget-list-more-arrow/siU"$res$match)) {
        
$result['error'] = 'Failed to parse.';
        return 
$result;
    }

    
$keywords $match[1];

    
$result['data'] = $keywords;
    return 
$result;
}
?>
 
Next Post Previous Post
No Comment
Add Comment
comment url