Something I whipped up today, grabs the keywords from rumler.com. Right now it just prints the keywords out to the screen, but it could easily be changed. All the data is saved in the $results array. Good Luck!
<?php
function rawdata($letter = 'A', $pn = '1'){
set_time_limit(10);
// setup and configure
$ch = curl_init();
$randnum = rand(1,9999999);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookiejar-$randnum");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookiejar-$randnum");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL,"http://www.rumler.com/google/adsense/top-paying-keywords.php?show=$pn&letter=$letter&sort=AvgCPC");
return curl_exec($ch);
}
function int2alpha($int_wert) {
if($int_wert == 26){
return 'Z';
}
if($int_wert%26>=1) {
$alpha_string=chr(($int_wert%26)+64).$alpha_string;
$alpha_string=int2alpha($int_wert/26).$alpha_string;
}
return $alpha_string;
}
function keywords($data){
//echo $data;
$info = array();
preg_match_all("/<tr align=\"left\"><td width=\"5%\"> <\/td><td width=\"20%\" valign=\"top\">(.*?)<\/td><td width=\"5%\"> <\/td><td width=\"20%\">(.*?)<\/td><td width=\"50%\">(.*?)<\/td><\/tr>/", $data, $info);
return $info;
}
function recordnum($data){
preg_match("/<span class=\"arial\">Found (.*?)<i>Google Adsense Top Paying Keywords<\/i>/", $data,$number);
return trim($number[1]);
}
for($char = 1;$char<=26;$char++){
$c = int2alpha($char);
$data = rawdata($c,1);
$pages = ceil(recordnum($data)/25);
echo "<h2><em>Keywords for</em> $c:</h2>\n";
for($page = 1;$page<=$pages;$page++){
$data = rawdata($c,$page);
$info = keywords($data);
$count = 0;
foreach($info[1] as $max){
//I just wanted the keywords so I didnt clutter the results page with the max/avg bid amounts
$results[$c]['max'][] = $max;
$results[$c]['avg'][] = $info[2][$count];
$results[$c]['keyword'][] = $info[3][$count];
//remove and use the results array at the bottom if you want to use for something else
echo $info[3][$count]."<br>\n";
$count++;
}
}
}
//print_r($results);
?>