By N2H

[Script] Récupérer le PR d’une page

Filed under Généralités SEO
Tagged as , , ,

Comme la plupart des homme de la SEO se basent encore sur le PR, je vous présente ci-dessous deux scripts pour récupérer le PageRank d’une page. Le premier est en Python et le deuxième est en Php. Bien sûr, ces scripts peuvent correspondre à toute sorte d’hattitude,mais il servira plus aux grey hat et aux black hat.

Il est à noter que les algo de Google changent avec le temps, de même que les appels pour récupérer le PR. Si les scripts suivants ne marchent plus c’est que la méthode est trop ancienne (les deux ont été testés le 8 Septembre 2009 et fonctionnent).

Script Python :

Le progamme script_pr.py :

#!/usr/bin/python

import urllib2
import re
import time
import sys

from urllib import urlencode
from pprint import pprint

HOST = "toolbarqueries.google.com"

def mix(a, b, c):
    M = lambda v: v % 0x100000000 # int32 modulo
    a, b, c = (M(a), M(b), M(c))
    a = M((a-b-c) ^ (c >> 13))
    b = M((b-c-a) ^ (a <<  8))
    c = M((c-a-b) ^ (b >> 13))

    a = M((a-b-c) ^ (c >> 12))
    b = M((b-c-a) ^ (a << 16))
    c = M((c-a-b) ^ (b >> 5))

    a = M((a-b-c) ^ (c >>  3))
    b = M((b-c-a) ^ (a << 10))
    c = M((c-a-b) ^ (b >> 15))

    return a, b, c


def checksum(iurl):
    C2I = lambda s: sum(c << 8*i for i, c in enumerate(s[:4]))
    a, b, c = 0x9e3779b9, 0x9e3779b9, 0xe6359a60
    lg  = len(iurl)
    k = 0
    while k <= lg-12:
        a = a + C2I(iurl[k:k+4])
        b = b + C2I(iurl[k+4:k+8])
        c = c + C2I(iurl[k+8:k+12])
        a, b, c = mix(a, b, c)
        k += 12

    a = a + C2I(iurl[k:k+4])
    b = b + C2I(iurl[k+4:k+8])
    c = c + (C2I(iurl[k+8:])<<8) + lg
    a, b, c = mix(a, b, c)
    return c


def GoogleHash(value):
    I2C = lambda i: [i & 0xff, i >> 8 & 0xff,  i >> 16 & 0xff, i >> 24 & 0xff]
    ch = checksum([ord(c) for c in value])
    ch = ((ch % 0x0d) & 7) | ((ch/7) << 2)
    return "6%s" % checksum(sum((I2C(ch-9*i) for i in range(20)), []))


def make_url(host, site_url):
    url = "info:" + site_url
    params = dict(client="navclient-auto", ch="%s" % GoogleHash(url),
                  ie="UTF-8", oe="UTF-8", features="Rank", q=url)
    return "http://%s/search?%s" % (host, urlencode(params))


# Where the fun begins

if __name__ == "__main__":
    if len(sys.argv) != 2:
        url = 'http://www.google.com/'
    else:
        url = sys.argv[1]

    if not url.startswith('http://'):
        url = 'http://%s' % url

    #print make_url(HOST, url)
    req = urllib2.Request(make_url(HOST, url))
    try:
        f = urllib2.urlopen(req)
        response = f.readline()
    except Exception, err:
        print err
        # print err.read()
        sys.exit(1)
       
    try:
        rank = re.match(r'^Rank_\d+:\d+:(\d+)', response.strip()).group(1)
    except AttributeError:
        print "This page is not ranked"
        rank = -1

    print "PagerRank: %d\tURL: %s" % (int(rank), url)

L’utilisation se fait de la manière suivante :

python script_pr.py http://black-hattitude.seo-blackh.at

Script Php :

La classe cacher.class.php : http://popstats.googlecode.com/svn/trunk/cacher.class.php

La classe google_pagerank.class.php : http://popstats.googlecode.com/svn/trunk/google_pagerank.class.php

L’utilisation :

require_once('./cacher.class.php');
require_once('./google_pagerank.class.php');
$rankObject = new GooglePageRank('http://black-hattitude.seo-blackh.at', 0);
echo $rankObject-> pagerank;


Sources

Python : http://blogmag.net/blog/read/91/Python_code_to_check_your_Google_PageRank

Php : http://code.google.com/p/popstats/


4 Comments

  1. Leonnito says:

    Merci pour le script ça fais longtemps que je cherchais. Je fais te faire un lien depuis mon blog mon cher Black Hattitude

  2. Jean says:

    Merci. Je viens d’essayer, mais j’ai un message d’erreur

    Forbidden

    Your client does not have permission to get URL /

    Il faut faire autre chose ?

Post a Comment

Pour être sûr que votre commentaire soit accepté, veuillez lire les règles pour poster un commentaire.

Your email is never published nor shared. Required fields are marked *

*
*