Page Rank Abfragen sind für SEOs und viele Webmaster die Lieblingsbeschäftigung. Thomas Lotze hat die berühmt berüchtigte WWW::Google::PageRank Library auf Python übertragen.

Download http://svn.thomas-lotze.de/public/googlepagerank/trunk.tar.gz

Leider ist das Python Modul nicht dokumentiert. Das Tool ist auch für die Kommando-Zeile gedacht. Allerdings bringt uns ein Blick auf das Starter-Script weiter ...


#!/usr/bin/env python
#
# Copyright (c) 2007 Thomas Lotze
# See also LICENSE.txt

"""Fetches page ranks for the given URLs from Google and prints them out.

Google page ranks range from 1 (unimportant) to 10 (important).
An empty page rank means Google has not yet assigned a rank to the URL.
"IO" instead of a page rank means there was an error contacting Google.
"RE" means Google's response could not be understood.
"""

import sys
import urllib
import tl.googlepagerank.interface as gpri


for target in sys.argv[1:]:
try:
rank = gpri.read_rank(urllib.urlopen(gpri.query_url(target)).read())
except IOError:
rank = "IO"
except ValueError:
rank = "RE"
else:
if not int(rank):
rank = ""

print "%2s %s" % (rank, target)


Daraus lässt sich wunderbar eine Klasse entwickeln, die anstatt einfach das Ergebnis auszugeben, eine Funktion enthält, die das Ergebnis in Dictionary ablegt.