#!/usr/bin/env python # -*- coding: utf-8 -*- """ This script accepts Domain, Search String and Google Locale arguments, then returns which Search String results page for the Google Locale the Domain appears on. Usage example: rankcheck {domain} {searchstring} {locale} Output example: rankcheck rassware.de 'BMW 325e' de The domain 'rassware.de' is listed in position 2 (page 1) for the search 'BMW 325e' on google.de """ __author__ = "Christian Raßmann (info@rassware.de)" __version__ = "$Revision: 1.0" __date__ = "$Date: 2009-09-02 22:44:24" import sys, re, urllib2 # check if all arguments were specified and whether help was requested: if len(sys.argv) < 4: if len(sys.argv) == 1: print "usage: rankcheck {finddomain} {keyphrase} {topleveldomain}"; print "`rankcheck --help' for more information." sys.exit() elif sys.argv[1] == '--help': print "usage: rankcheck {finddomain} {keyphrase} {topleveldomain}" print "Check the Search String page ranking of a Domain on a specific Google Locale" print "\nExample: rankcheck rassware.de 'BMW 325e' de" print "\nReport bugs to ." sys.exit() else: print "usage: rankcheck DOMAIN SEARCHSTRING LOCALE"; print "`rankcheck --help' for more information." sys.exit() # some initial setup: useragent = 'Mozilla/4.0 (compatible; MSIE 6.0)' finddomain = sys.argv[1] keyphrase = sys.argv[2] keyphrase_urlcode = sys.argv[2].replace(' ','+') topleveldomain = sys.argv[3] urlstr = 'http://www.google.' + topleveldomain + '/search?hl=' + topleveldomain + '&q=' + keyphrase_urlcode html = '' for i in range(0, 10): requesturl = urlstr + '&start=' + str(i * 10) #print requesturl url=urllib2.Request(requesturl) url.add_header('User-Agent',useragent) html = html + urllib2.urlopen(url).read() result = 0 counter = 0 url=unicode(r'(