forked from pkrumins/xgoogle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added an example program finds how the target_domain ranks for target…
…_keyword keyword on google
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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) | ||
|