Rank checking on Google’s SERPs
Since everyone else seems to be releasing free/not quite free Google SERP ranking trackers, in the spirit of "what the hell they'll change the code tomorrow anyway", here's the (Perl) regular expression I've been using for my own Google SERP tracker:
-
while ($content =~ m{<div class=g(?:[^>]*?)><!--m-->(?:.*?)<h2 class=r><a href="([^"]*?)" class=l onmousedown="return (?:clk|rwt)\(this(?:\.href)?,'[^']*','[^']*','res','(\d+)','[^']*'(?:,'[^']*')?\)">(.*?)</a>.*?</h2>.*?<(?:font size=-1|div class=(?:sml|std))>(?:((?:\w|<b>).*?)<br>.*?)?<span class=a>(.*?)</span>(?:<nobr>)?(?:<a class=fl href="([^"]*?)"(?:[^>]*?)>Cached</a> - )?(?:<a class=fl href="([^"]*?)">Similar pages</a>)?(?:</nobr>)?(.*?)</(?:font|div)>.*?<!--n-->}gi) {}
Of course it's up to you to figure out the rest of the code surrounding the regex
Will Google ever stop this madness by actually creating a decent API to their results pages?
Update: Aargh - thanks to Wordpress's impossible handling of smart-quotes, that code is broken by the smart quotes peppered throughout it - do a search and replace to fix that...
Tags: Google, regex, regular expression, serps








June 16th, 2008 at 11:09 pm
Actually, I haven’t yet decided if I’ll charge for my tool or not. It’s free for now, at least
Fun what you can do with regular expressions.
Eric
aka “The Toolinator”
June 17th, 2008 at 12:11 pm
Very true - your link text has now been swapped around with Joost’s, which is charged for
February 5th, 2009 at 3:49 pm
FYI The link above to the “not quite free” product is unavailable. I found a tool at http://www.digitalpoint.com/tools/keywords/ haven’t tested it yet gotta get my google API which somehow dissappeared from the site I need to get rankings on.