Skip to Main Content
SEO Warrior
book

SEO Warrior

by John I Jerkovic
November 2009
Beginner content levelBeginner
496 pages
13h 46m
English
O'Reilly Media, Inc.
Content preview from SEO Warrior

Chapter 6

searchPhraseReportGoogle.pl

#!/usr/bin/perl
#----------------------------------#
#  PROGRAM:  Search Phrase Report  #
#----------------------------------#

$numArgs = $#ARGV + 1;

%googleDirCnt = ();

foreach $argnum (0 .. $#ARGV) {
   print "Processing $ARGV[$argnum] file\n\n";
   $LOGFILE = "$ARGV[$argnum]";
   open(LOGFILE) or die("Could not open log file: $ARGV[$argnum].");
   foreach $line (<LOGFILE>) {
     #do Google analysis
     if(($line =~ /q=/) && ($line =~ /google/)) { @tmp1 = split ('GET ',$line); @tmp2 = split (' ', $tmp1[1]); @tmp3 = split ('q=', $tmp1[1]); @tmp4 = split ('\&', $tmp3[1]); #do some cleanup $tmp4[0] =~ s/\+/ /; $tmp4[0] =~ s/\%20/ /g; $tmp4[0] =~ s/\%3C/\</gi; $tmp4[0] =~ s/\%3E/\>/gi; $tmp4[0] =~ s/\%23/\#/g; $tmp4[0] =~ s/\%22/\"/g; $tmp4[0] =~ s/\%25/\%/g; $tmp4[0] =~ s/\%3A/\:/gi; $tmp4[0] =~ s/\%2F/\//gi; $tmp4[0] =~ s/\%2B/\+/gi; @tmp5 = split ('\"', $tmp4[0]); $tmpKey = "<tr><td>".$tmp2[0]." </td><td>".$tmp5[0]."</td>"; $googleDirCnt{$tmpKey} = $googleDirCnt{$tmpKey} +1; } } close(LOGFILE); } open (FP, '>keywordsummary.html'); print FP "<html><head><title>Keyword Summary</title><head>"; print FP "<body><strong>Google Summary</strong>"; print FP "<table width=400><tr><td><b>Resource/URL</b></td><td><b>Keyword</b></td>"; print FP "<td><b>Count</b></td><tr>"; foreach $key (sort hashValueDescendingNum (keys(%googleDirCnt))) { print FP $key."<td>".$googleDirCnt{$key}."</td></tr>"; } print FP "</table></body></html>"; close (FP); sub hashValueDescendingNum { $googleDirCnt{$b} ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The SEO Battlefield

The SEO Battlefield

Anne Ahola Ward

Publisher Resources

ISBN: 9780596804749Errata Page