Mark Sanborn Mark Sanborn Fishing Mark Sanborn

Coder, Entrepreneur, Blogger, and Coffee Addict

Check Google PageRank with Perl

I am on a huge Perl kick lately. I have been making tons of different perl scripts for many different uses. Some of them useful and some are just plain silly. In this post we are going to talk about making an easy script that will go out and check the pagerank of any site that you want. Then we will make the script run through PHP so we can display our result on a website.

The Perl

 
This is a really simple perl script. Basically all we are doing here is calling a third party perl module called, “WWW::Google::PageRank“. Perl like many language is known for having a repository of easy to use modules that are already made so you don’t have to do any extra coding. This repository is called CPAN. No heavy coding in this example.

#!/usr/bin/perl
# Library location for custom modules on dreamhost
use lib '/home/marcrosoft/perlmods/share/perl/5.8.4/';
use WWW::Google::PageRank;

$url = $ARGV[0];

if (defined($url)) {
        my $pr = WWW::Google::PageRank->new;
        print scalar($pr->get($url)), "\n";
} else {
        print 'Page not specified!'. "\n";
}

The first couple of lines initiate perl and get library files. If you are using Dreamhost as your webhost you can follow this guide to download perl library modules into your home directory.

The ‘$ARGV[0];‘ part of the code simply means to accept a paramter when executing the script. So you can do stuff like, ‘perl myperl.pl someArgument‘.

The rest of the code is just initilizing the module or printing an error message if no argument is passed.

To execute your code do, perl whateverYouNamedYourScript.pl http://www.yoursite.com‘.

The PHP Code

 
Once you have your working perl file you should be able to execute it from your shell. If all goes well it should return an integer between 1 and 10 representing the site’s google page rank. Now if you want to make PHP display the rank you can use the ‘shell_exec‘ command to execute and return the output.

<?php
$output = shall_exac("perl /home/username/Pagerank.pl http://www.yourpage.com");
echo "The page rank for this site is: $output";
?>

Note: You must change, shall_exac to shell_exec. Due to the security settings on this domain I can’t even post the correct command anywhere near php code without getting an error in wordpress. Kinda weird but I am not complaining.

If you noticed in the above code you usually have to specify the absolute path to the perl file. Some sites are also setup to only run executable files from outside of the web path for security reasons. This is why I stored my file in my home directory.

Thats it!



This entry was posted in Programming. Bookmark the permalink.

3 Responses to Check Google PageRank with Perl

  1. Pingback: Checking if a site is penalised by Google - Jamie’s Digital Blog

© 2011 All rights reserved

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|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165|166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184|185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|208|209|210|211|212|213|214|215|216| generic buying erythromycin alesse next day delivery without a prescription motilium no prescription needed buy cytotec pills canadian pharmacy no prescription needed provera actos by internet buying orlistat pharmacy without prescription lisinopril no prescription needed purchase femara medication buy lipitor cod actonel buy online cheap buy carbozyne online without prescription femara prescription discounts elavil without prescriptions pills buying isotretinoin online pharmacy trazodone no prescription order no prescription metformin birth control no prescriptionAccutane Online Doxycycline online Buy Cheap Lexapro Online No Prescription Prednisone Online Buy Accutane No Prescription