Chapter 13

getRankings.pl

#!/usr/local/bin/perl ########################################### # File: getRankings.pl # # Description: This script queries SEs # # to produce rankings report # ########################################### ### Basic setup part $numOfArgs = $#ARGV + 1; $originalkeywordphrase = ""; $targeturl=""; if ( ($numOfArgs == 0) || ($numOfArgs == 1) || ($numOfArgs < 0)) { print ("\n\nUsage: perl getRanking.pl [TargetURL] [Keyword]\n"); print ("\nOR\n"); print ("\nUsage: perl getRanking.pl [TargetURL] [Keyword1] [Keyword2] ... [KeywordN]\n\n"); exit(0); } $targeturl=$ARGV[0]; if ( $numOfArgs == 2){ $originalkeywordphrase = $ARGV[1]; }else { foreach $argnum (1 .. $#ARGV) { $originalkeywordphrase = $originalkeywordphrase . " " . $ARGV[$argnum]; #remove leading & trailing spaces $originalkeywordphrase =~ s/^\s+//; $originalkeywordphrase =~ s/\s+$//; } } $keywordphrase= $originalkeywordphrase; $keywordphrase =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; # define Source Urls $listingNo=100; $gurl= "http://www.google.com/search?num=$listingNo&hl=en&safe=off&q=$keywordphrase&sa=N"; $burl= "http://www.bing.com/search?q=$keywordphrase&first=1&count=100&"; ### get SERP pages part # get google SERP $gserp = `wget "$gurl" --user-agent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)" --output-document="gserp.html" --cookies=off`; # get Bing SERP $bserp = `wget "$burl" --user-agent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)" --output-document="bserp.html" --cookies=off`; ...

Get SEO Warrior now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.