1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

[Share] Grab google trend

Discussion in 'Pemrograman Web' started by xrvel, May 6, 2014.

  1. xrvel

    xrvel Super Hero

    Joined:
    Oct 21, 2007
    Messages:
    2,873
    Likes Received:
    947
    Location:
    Di sini
    Karena ada salah satu email yg bertanya cara grab google trend di negara tertentu, saya buatin threadnya sekalian di sini :D

    Kode di bawah menggunakan 'p1' sebagai country code amerika.
    Cara lihat country code lain, buka link ini
    Code:
    http://www.google.com/trends/hottrends
    Pilih negaranya dari dropdown, contoh Brazil, maka URL di browser akan jadi
    Code:
    http://www.google.com/trends/hottrends#pn=p18
    Maka kode Brazil = p18

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

    PHP:
    <?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;
    }
    ?>
    [hr][/hr]
    Pake ini coba :D

    PHP:
    <?php
    header
    ('Content-type: text/plain');

    //$keyword = my_get_google_hot_trend('p21');
    //print_r($keyword['data']);

    $keyword my_get_google_keyword('tattoo');
    print_r($keyword['data']);

    //////////////

    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_keyword($keyword) {
        
    $result = array(
            
    'data' => array(),
            
    'error' => ''
        
    );

        
    $res xrvel_curl('http://www.google.com/trends/fetchComponent?hl=en-US&q='.urlencode($keyword).'&content=1&cid=TOP_QUERIES_0_0&export=5&w=300&h=420');

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

        
    $res str_replace(array("\r""\n""\t"), ''$res);
        
    $res preg_replace('/([ ]){2,}/'' '$res);

        if (!
    preg_match_all("/\('top keywords drilldown'\)\;\" \>(.*)\<\/a\>/siU"$res$match)) {
            
    $result['error'] = 'Failed to parse.';
            return 
    $result;
        }

        
    $keywords $match[1];

        
    $result['data'] = $keywords;
        return 
    $result;
    }

    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;
    }
    ?>
    Hasilnya :
    Code:
    Array
    (
        [0] => tattoos
        [1] => tattoo designs
        [2] => tattoo girl
        [3] => dragon tattoo
        [4] => tatoo
        [5] => tattoo ideas
        [6] => tatto
        [7] => how to tattoo
        [8] => tribal tattoo
        [9] => tattoo shops
    )
    
    [hr][/hr]
    script masih mentah gan, utk apa tergantung kreatifitas kita.

    kalau kita punya AGC, keyword itu bisa ditampilkan di halaman web kita berupa live link ke halaman search utk men-generate AGC yg berkaitan dengan google trend. :)
    Bisa juga berguna utk yg maen wp robot.

    Biasanya berguna utk yg maen auto-auto'an.
    Kalau utk yg maen manual, tidak berguna :)
     
    Last edited: May 7, 2014
    xtmxady, kited, ingkong and 36 others like this.
  2. itilitit

    itilitit Hero

    Joined:
    Mar 31, 2012
    Messages:
    581
    Likes Received:
    26
    Location:
    bandung
    kalo misal grabbing untuk KW tertentu bisa gan??? misal trend/related trend KW tatto...
     
    azf81 likes this.
  3. xrvel

    xrvel Super Hero

    Joined:
    Oct 21, 2007
    Messages:
    2,873
    Likes Received:
    947
    Location:
    Di sini
    Ada URL sampelnya nggak di google?

    Update:

    Kaya gini? :D
    Code:
    http://www.google.com/trends/fetchComponent?hl=en-US&q=tattoo&content=1&cid=TOP_QUERIES_0_0&export=5&w=300&h=420
    Update #2: Cek post pertama, sudah saya update kodenya.
     
    Last edited: May 7, 2014
  4. xpro99

    xpro99 Banned

    Joined:
    Nov 5, 2013
    Messages:
    1,249
    Likes Received:
    113
    Location:
    /home/public_html
    liat daftar kode negara nya dmn ya gan?


    n.b : udh nemu gan :D
     
  5. itilitit

    itilitit Hero

    Joined:
    Mar 31, 2012
    Messages:
    581
    Likes Received:
    26
    Location:
    bandung
    thans mastah..
    bookmark dulu...
     
  6. Agus Pian

    Agus Pian Blogger Super Ngeraos

    Joined:
    Apr 19, 2013
    Messages:
    3,355
    Likes Received:
    130
    Location:
    NTB
    terus gmana cara nambah script itu gan?
     
  7. suriemie

    suriemie Ads.id Pro

    Joined:
    Sep 15, 2006
    Messages:
    404
    Likes Received:
    53
    lumayan jadi ada ide.. makasih scriptnya.. pernah coba gak kalo requestnya banyak bakal diblock google ato ngga?

    o iya sekalian nanya soalnya kayaknya pengalaman sama grab data dari google, bisa grab hasil search google berdasarkan keyword tertentu yang dibuat 24 jam terakhir gak? :D

    makasih sebelumnya :)
     
    Last edited: May 7, 2014
  8. qomareza

    qomareza Newbie Level 3

    Joined:
    Dec 24, 2012
    Messages:
    2,409
    Likes Received:
    121
    Location:
    Kota Tanah Air
    like dulu lah :D
     
  9. maintangankiri

    maintangankiri Hero

    Joined:
    Aug 2, 2011
    Messages:
    564
    Likes Received:
    18
    Itu scriptnya buat dimasukin di postingan maksudnya y bro?
     
  10. Cemonggaul

    Cemonggaul Cemonggaul Network

    Joined:
    Nov 24, 2012
    Messages:
    632
    Likes Received:
    57
    Location:
    Cemonggaul Network
    udah ditinggalin like
    sapa tau mau jelasin lebih detail lagi ke nubitol ini
    soale rung mudeng cara penggunaane script itu dimana :lol:
     
    maswardi likes this.
  11. MRahmat

    MRahmat Newbie

    Joined:
    May 6, 2014
    Messages:
    27
    Likes Received:
    0
    Itu script php gan :entahlah: bukan untuk postingan
     
  12. sandrabehan

    sandrabehan Ads.id Starter

    Joined:
    Nov 1, 2013
    Messages:
    86
    Likes Received:
    0
    Location:
    Jawa
    mantap gan
     
  13. Cemonggaul

    Cemonggaul Cemonggaul Network

    Joined:
    Nov 24, 2012
    Messages:
    632
    Likes Received:
    57
    Location:
    Cemonggaul Network
    iyo tau masbro kalo itu script PHP
    cuman yang belum ngeh cara makenya gimana? apa dimasukin ke hosting kita ato gimana kan masih lom muden om :monyong:
    maklum lah om nubitol :malu:
     
  14. alhijr

    alhijr Super Hero

    Joined:
    Feb 27, 2010
    Messages:
    4,392
    Likes Received:
    862
    Location:
    PIN : 7568977
    Keren ninggalin jejak dulu koding trends ini cocok buat ide cepat
     
  15. chiman

    chiman Hero

    Joined:
    Jul 16, 2007
    Messages:
    732
    Likes Received:
    33
    Location:
    Bali
    cocok buat dijadiin web ageceeeehh..

    :D
     
    xrvel likes this.
  16. Syailendra

    Syailendra Siswa Ads-id

    Joined:
    Jan 14, 2012
    Messages:
    1,179
    Likes Received:
    189
    Location:
    Indonesia
    Langsung Praktek Ah Thanks Alot Mas Bro :D
     
  17. alfianjoe

    alfianjoe Newbie

    Joined:
    Feb 9, 2013
    Messages:
    27
    Likes Received:
    0
    Location:
    depan laptop saja
    nice share suhu...mencoba untuk menerapkan
     
  18. AsunaYuki

    AsunaYuki Super Hero

    Joined:
    Nov 29, 2012
    Messages:
    1,210
    Likes Received:
    139
    Location:
    Sumedang
    waw ,, , banyak yg mau praktek, tapi blum ada yg mau ngejelasin gmna cara makenya, Bersabarlah wahai Saudaraku para Nubi :komunis:
     
  19. T4m3n6

    T4m3n6 Ads.id Fan

    Joined:
    Apr 7, 2013
    Messages:
    207
    Likes Received:
    6
    Lumayan nich buat referensi nambah-nambah kode
     
  20. xrvel

    xrvel Super Hero

    Joined:
    Oct 21, 2007
    Messages:
    2,873
    Likes Received:
    947
    Location:
    Di sini
    Mungkin diblock kalau terlalu sering. Main aman aja misal sehari 2x, sisanya dicache dalam database / file txt :D


    script masih mentah gan, utk apa tergantung kreatifitas kita.

    kalau kita punya AGC, keyword itu bisa ditampilkan di halaman web kita berupa live link ke halaman search utk men-generate AGC yg berkaitan dengan google trend. :)
    Bisa juga berguna utk yg maen wp robot.

    Biasanya berguna utk yg maen auto-auto'an.
    Kalau utk yg maen manual, tidak berguna :)
     
    Cemonggaul likes this.

Share This Page