Google Trend

This morning I was so excited to start mining google trend. If you are new with Google Trend, it will show keywords that are recently getting popular. You will get 100 top popular keywords. This keyword list is updated every hour.

I’m planning to populate them, mining the data in order to get the ‘hot’ and long term profitable keyword that I can use to build adsense websites.

I will show you how to do this with a simple PHP script.

1) Create a new database

?Download setup.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
CREATE TABLE `log` (
  `log_id` int(11) unsigned NOT NULL auto_increment,
  `data` text collate latin1_general_ci,
  `created_at` char(10) collate latin1_general_ci default NULL,
  PRIMARY KEY  (`log_id`),
  KEY `date` (`created_at`)
);
 
CREATE TABLE `trend` (
  `keyword_id` bigint(20) unsigned NOT NULL auto_increment,
  `keyword` varchar(255) collate latin1_general_ci default NULL,
  `created_at` char(10) collate latin1_general_ci default NULL,
  PRIMARY KEY  (`keyword_id`),
  KEY `kw` (`keyword`),
  KEY `date` (`created_at`)
);

2) The next script shows the logic how I fetch google trend data then parse its content and store it into database. I run this script hourly with cronjob.

?Download fetch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
 
  include "global.php";
 
  $url = 'http://www.google.com/trends/hottrends/atom/hourly';
 
  $raw = file_get_contents($url);
 
  $arr = explode('<li>', $raw);
  //print_r($arr);
 
  foreach ($arr as $k => $v) {
    if ($k>0)
      $arr2[$k] = trim(strip_tags($v));
  }
 
  $temp_100 = explode(']]>', $arr2[100]);  
 
  $arr2[100] = trim($temp_100[0]);  
 
  //print_r($arr2);
 
  $record['data'] = serialize($arr2);
  $record['created_at'] = time();
 
  $gt->db->AutoExecute('log', $record, 'INSERT');
  unset($record);
 
  foreach ($arr2 as $k => $v) {
    $record['keyword'] = $v;
    $record['created_at'] = time();
 
    $gt->db->AutoExecute('trend', $record, 'INSERT');
  }
 
  print "DONE.";
?>

In a day I expect to get 100 x 24 hours = 2400 keywords. From this number, I’d like to know which keywords that are appear more often than the others and then they will be considered as the good one, the high demand keywords.

I can use the following query to get them.

1
select count(keyword_id) as c, keyword from trend where created_at > 0 group by keyword order by c desc

As a result:

the top keyword list

If we need them in a certain time duration, we can easily play with created_at condition.

In next article I want to show you how we can get more precise and more profitable keyword using this google trend database.

One Response to “I start mining google trend”

  • Aaron says:

    Thanks alot for this. I can see you include a file called global.php – from where can I get this?

Leave a Reply