Have you ever wondered where your site ranks on google for a given search?
Try this ruby script out to find out (be nice with it!).
You'll need ruby installed of course. Also do a
gem install hpricot
since this requires the hpricot gem to be installed.
It will search up to 20 pages deep on google (I wouldn't recommended altering this since nobody is going to search more than 20 pages deep for your webpage).
grank.rb:
require 'rubygems'
require 'open-uri'
require 'hpricot'
def print_usage()
puts "usage: " + $FILENAME + "\"search\" domain"
end
if (ARGV.length < 2)
print_usage()
exit
end
search = URI.escape(ARGV[0])
search_for_domain = ARGV[1]
found = false
page_num = 0
max_pages = 20
while found == false and page_num < max_pages
page_num += 1
result_num = (page_num-1) * 10
elements = Hpricot.parse(
open(
"http://www.google.com/search?q=#{search}&start=#{result_num}&sa=N")
).search("ol li.g h3.r a")
elements.each do | el |
host = URI.parse(el.attributes['href']).host rescue next
if (host.include?(search_for_domain) or search_for_domain.include?(host))
found = true
break
end
end
if (found)
puts "Found on page #{page_num}"
exit
end
end
puts "search #{search} was not found within #{max_pages}"
Usage:
ruby grank.rg "Your Search" "yourdomain.com"
