Friday 27 February 2009

Simple PHP Multi Keyword Google Rank Checker

0 comments
I had a couple of commenters on my post about the Google Blogsearch URL Scraper ask whether it could be turned into a google rank checking script.
Well, in a nutshell, the answer to that question was no, but that’s not to say that the Pimp didn’t have one in his arsenal, and that he’d be prepared to share it!
So here it is, and as always, for those who want to know how it works, the code is extremely well commented (you’re going to need to go in and replace all the single and double quotes after you’ve copied the code below, as wordpress screws them up (or download the script here):
ob_start();
//put your site’s URL here, but leave off the http://www
$url = “pimpmypagerank.com”;
//put all the keywords you want to check here, make sure you leave the single quotes and commas intact for each keyword
$keywords = array(
‘google scraper’,
‘php script to get pagerank’,
‘Simple PHP Google Bot Cloaking Script’,
);
//Just tells us what URL we’re checking rankings for
echo “

Google SERPS For ” .$url. “

”;
//start to run through each of the keywords
foreach($keywords as $keyword) {
//set our counter at zero, so we can work out what the ranking of the page
$count = 0;
//make a URL that we can query Google with
$search = “http://www.google.com/search?q=” .urlencode($keyword). “&num=100″;
//now go get that page
$google = file_get_contents($search);
//funky regular expression stuff to find our URL in the results
$description= (’/<h3 class=r><a href=\”(.+?)\” class=l/’);
preg_match_all($description,$google,$match);
//start looping through each of the results on the page
foreach( $match[1] as $value){
//Add one to the counter after we check each of the results
$count = $count + 1;
//check each of the 100 results from google, to see if our URL is in it.
if(strstr($value, $url)) {
//if this particular result has our URL in it, print it to the page, along with the ranking ($count variable from above)
echo $keyword. ” - ” .$count. “
”;
ob_flush();
flush();
}
}
//Have a bit of a rest before we go check the next keyword, so we don’t get booted from the Goog’
sleep(rand(30,60));
}
?>
And there you have it!
Tomorrow, the same script, but to get Yahoo! results…

Comments

0 comments to "Simple PHP Multi Keyword Google Rank Checker"

Post a Comment

Labels

 

Copyright © 2009 by Free Blogger Themes. Revolution 2 Church Theme by Brian Gardner. Converted into Blogger Template by Bloganol dot Com