Created
October 12, 2013 10:36
-
-
Save manudatta/6948491 to your computer and use it in GitHub Desktop.
Wrote this program in 2003 to find google rank of a site given search items. Use it on your own risk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! path to python | |
# copyright manu.datta gmail.com | |
import string | |
import getopt | |
import sys | |
import ConfigParser | |
import re | |
UsageErr ='googlerank -n <number> -d <website> -c <domain> <Search Word>' | |
cfg = ConfigParser.ConfigParser() | |
cfg.read('grank.ini') | |
sys.path.append(cfg.get('PyGoogle','HOME')) | |
import google | |
google.LICENSE_KEY=cfg.get('Google','KEY') | |
myargs = sys.argv[1:] | |
# split the args | |
optlist,args=getopt.getopt(myargs,'n:d:c:') | |
webSite='' | |
query='' | |
rtext="" | |
nums = 100 | |
bWebSite = 0 | |
# now send the google following query | |
#print optlist | |
for o,a in optlist: | |
if(o=='-c'): | |
rtext="country%s" % a.upper() | |
#query=query+' site:'+a | |
elif(o=='-d'): | |
webSite = a | |
#print 'WS'+webSite | |
bWebSite = 1 | |
elif(o=='-n'): | |
nums=int(a,10) | |
if bWebSite == 0: | |
print 'Error: No Website specified' | |
print UsageErr | |
sys.exit(2) | |
searchWords='' | |
for words in args: | |
searchWords = searchWords+' '+words | |
searchWords=searchWords[1:] | |
if searchWords=='': | |
print 'Error: No Search Words' | |
print UsageErr | |
sys.exit(2) | |
query=query+' '+searchWords | |
left = nums | |
bThere = 0 | |
counter = 0 | |
r=re.compile("^http://(.*)"+webSite+"/(.*)$") | |
while ( left > 0 and bThere==0): | |
searchRes=google.doGoogleSearch(query,start=counter,restrict='%s' % rtext).results | |
left = left - len(searchRes) | |
for sites in searchRes: | |
counter = counter + 1 | |
if r.match(sites.URL): | |
print "%s is ranked %s for search terms:%s (restrict=%s)" % (webSite,str(counter),query,rtext) | |
bThere = 1 | |
break | |
if ( bThere != 1): | |
print "%s not ranked in first %s for search terms:%s (restrict=%s)" % (webSite,str(nums),query,rtext) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment