Skip to content

Commit

Permalink
added an example program finds how the target_domain ranks for target…
Browse files Browse the repository at this point in the history
…_keyword keyword on google
  • Loading branch information
pkrumins committed Nov 30, 2009
1 parent 939ce9a commit 0268a12
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python
#
# This program finds how the target_domain ranks for target_keyword keyword.
#
#

import re
from urlparse import urlparse
from xgoogle.search import GoogleSearch, SearchError

target_domain = "catonmat.net"
target_keyword = "python videos"

def mk_nice_domain(domain):
"""
convert domain into a nicer one (eg. www3.google.com into google.com)
"""
domain = re.sub("^www(\d+)?\.", "", domain)
# add more here
return domain

gs = GoogleSearch(target_keyword)
gs.results_per_page = 100
results = gs.get_results()
for idx, res in enumerate(results):
parsed = urlparse(res.url)
domain = mk_nice_domain(parsed.netloc)
if domain == target_domain:
print "Ranking position %d for keyword %s on domain %s" % (idx+1, target_keyword, target_domain)

0 comments on commit 0268a12

Please sign in to comment.