Home PageRank.py – Get google PageRank with python
Post
Cancel

PageRank.py – Get google PageRank with python

I spend several hours trying to find a python script that would return google PageRank with a python script. There seems to be a script out there that was working in 2010 from Corey Goldberg. It is not working for me. I looked around for quite a bit till I found a python script on GitHub. The script is sponsored by Phurix and uses toolbar queries. I decided to republish it with a small modification:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<pre lang="py" toggle="no">#!/usr/bin/env python

# Google Pagerank Checksum Algorithm (Firefox Toolbar)
# Downloaded from http://pagerank.phurix.net/
# Requires: Python >= 2.4

# Versions:
# pagerank2.py 0.2 - Fixed a minor formatting bug
# pagerank2.py 0.1 - Public release

# Settings
prhost='toolbarqueries.google.com'
prpath='/tbr?client=navclient-auto&ch=%s&features=Rank&q=info:%s'

# Function definitions
def GetHash (query):
    SEED = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer."
    Result = 0x01020345
    for i in range(len(query)) :
        Result ^= ord(SEED[i%len(SEED)]) ^ ord(query[i])
        Result = Result >> 23 | Result << 9
        Result &= 0xffffffff
    return '8%x' % Result

def GetPageRank (query):
    import httplib
    conn = httplib.HTTPConnection(prhost)
    hash = GetHash(query)
    path = prpath % (hash,query)
    conn.request("GET", path)
    response = conn.getresponse()
    data = response.read()
    conn.close()
    return data.split(":")[-1]

if __name__ == "__main__" :
    print GetPageRank("https://schurpf.com/")

I did modify the original script a tiny bit to only return the page rank as a string. That is it. I hope it helps you, let me know comments or questions and I will try to answer as good as I can.

This post is licensed under CC BY 4.0 by the author.
Trending Tags