Posted by on Oct 4, 2011 in Programming, World Wide Web | 0 comments

I wanted to see where certain sites rank for a given search term. Normally this is accomplished by heading to Google, entering your search query and potentially paging through N pages using ctrl + f until I find the site I’m looking for. Obviously there is a better way. Searching around I found only questionable sites offering the service so I figured it wouldn’t be that hard to build.

Google.groovy:

It simply posts the search criteria to Google and loops through the results to find the matching URL. If the provided ‘pattern’ is found it dumps out the position and the URL found. If it doesn’t find anything it exits without displaying anything. The PREF cookie is obtained by using your favorite web developer tools such as Chrome or FireBug. Before you grab the value though you need to visit http://www.google.com/preferences and disable Google Instant and increase the number of results if you are interested in more than just the first 10. I like using Google Instant so I did this in a Chrome Incognito window so my preferences are left untouched. I also wanted to see what the general public saw. If I ran the script as myself my +1’s etc… would skew the results to show me what I like.

The app takes a bit of time to run the first time as Grape has to download the dependencies, TagSoup and HttpBuilder. Even subsequent runs aren’t as fast as you would think they should be. I’m guessing it is Grape checking to make sure all the dependencies exist locally.

UPDATE: It appears that sometime after I started to play with this stuff Google released a new version of Analytics that has the ability to associate a Webmaster Tools property to an Analytics property under Traffic Sources –> Search Engine Optimization –> Queries. It allows you to cross reference search queries used to arrive at your site and Country. You are still shown the average position but it has a pretty graph.

Appears to have been added on September 8th/2011: http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=1120006

twittergoogle_pluslinkedin