As a part of Search Engine Optimization (SEO) you may want to be aware of your websites (or clients websites) page rank on Google. After some researching I’ve found the following solutions to be best. I’ll be presenting a few options here, first we’ll cover how to look it up on prchecker.info. Second we’ll be covering how to look up the page rank using a perl script and finally we’ll cover how to look up your page rank with the perl script and update a mysql database with the information (for long term tracking and/or tracking multiple websites.)
PRChecker.info
Getting the page rank for prchecker.info is simple enough. Just browse to the website and enter in the domain name of the website you would like to view the page rank for, after verifying your humanity to page rank will be displayed for you.
That’s easy enough for a single check here and there but what if the website wants to always know it’s own page rank, or wants its visitors to be aware of the page rank? That’s where prchecker.info allows for copy and pasting some code to allow a small button to be added to the website that will always have the current rank on it. This button is available to grab once you’ve done your initial lookup. Simply copy/paste the code into your website wherever you’d like the page rank to show up and your button will appear and stay up to date.
Example Button
Ok, now we’ve got the super simple stuff out of the way let’s have some fun!
Google Page Rank Perl Script
First off you are going to need the following zip file [broken link]. Place the google_pr.pl file wherever you would like to run it from and place the WWW folder in a child folder / directory to the location of the google_pr.pl file.
For example:
/home/sudobash/bin/google_pr.pl
/home/sudobash/bin/WWW
A look at the perl script
#!/usr/bin/perl #use warnings; #use strict; use lib '/parent/path/to/your/WWW/directory/'; use WWW::Google::PageRank; my $pr = WWW::Google::PageRank->new; my $page = $ARGV[0]; # Default websites to check if no parameter is specified on the command line # This should never trigger once we run it from our PHP page. my @sites = ( 'http://www.sudobash.net', 'http://www.5pointbody.com', 'http://www.wordpress.org' ); if(!$page) { foreach(@sites) { print "$_ : "; print scalar($pr->get($_)), "\n"; } } else { # print "$page : "; print scalar($pr->get($page)), "\n"; }
Now to run this from the command line we can do the following 2 options.
Run the script with no parameters. This will lookup any of the websites we listed in the @sites array.
/usr/bin/perl /home/sudobash/bin/google_pr.pl
Which will give us the following output:
http://www.sudobash.net : 2 http://www.5pointbody.com : 2 http://www.wordpress.org : 9
Now if that information is all you wanted you can just stop now. But if you’d like to work with PHP and MySQL to track multiple websites, read on!
PHP & MySQL Page Rank Tracking with Perl Script
First off we’re going to assume that you have a database already setup and know how to connect to it. If you don’t already know how to code PHP to connect to your database swing by the following post in regards to dbconnect.php.
Make whatever table you’d like (or add to an existing one), for example ‘domains’. Then we’ll be using something like the following file (modify to fit your own environment and needs).
<?php /********************************************************* * * * This file is responsible for nightly updates * * of each websites google page rank * * * * Runs every night at 2250 CST * * * * Author : Scott Rowley * * Written : 05/04/2012 * * * *********************************************************/ require_once('dbconnect.php'); // Get all of our domains $sql = "SELECT domain_name FROM domains"; $res = mysql_query($sql)or die(mysql_error()); // Loop through our list of domains and look up the // Page Rank for each one, store the new number in the // database. while($row = mysql_fetch_array($res)){ $domain_name = $row['domain_name']; // I store my domains like 'sudobash.net' not 'http://sudobash.net' so we'll add http:// to the // front of each domain name. $url = 'http://'.$domain_name; // Perform the actual look up for the current domain name $pagerank = `/usr/bin/perl /home/sudobash/bin/google_pr.pl $url`; if($pagerank==''){ $pagerank = 0; } // Update the database with the current page rank $sql_pr = "UPDATE domains SET page_rank='$pagerank' WHERE domain_name='$domain_name'"; $res_pr = mysql_query($sql_pr)or die(mysql_error()); }
And now we can retrieve the most recent page rank at any time, for example in a backend that tracks all of your websites, their stats, etc.
Credits
This program uses Yuri Karaban’s WWW::Google::PageRank Perl module to obtain page rankings from Google’s server. That module, in turn, uses the LWP::UserAgent and URI::Escape modules, both developed by Gisle Aas.
Google and PageRank are trademarks of Google Inc.
Tidy piece of code. Great stuff.
A good alternative to prchecker.info is prfind.com, I find it much simpler to use.
Thanks for the perl script.
Very nice NJ! I’ll update the post and use this page instead as soon as I get a few minutes.