[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: pagerank
Guest
Подскажите работающий скрипт по определению pagerank?
Данный код у меня не работает:
<?php
/*
The source code for the PageRank script is below.
Copy & Paste the code between the <?php and ?> tags below into some file with a .php extension, e.g. pagerank.php.
You can use it in PHP as follows. To get the Toolbar PageRank:
$url = "www.google.com";
echo "PageRank of " . $url . " is:<br />" . getrank($url);
To use the getrealrank() function, you will need an xmltoarray function. Some can be found at the PHP.net entry for xml_parse_into_struct: www.php.net/xml_parse_into_struct
*What the getrealreank() function does is parse the Google XML page for the URL, looking for any <U> tag that matches the URL, or some permutation of it (with or without the http:// prefix, www. prefix, or a trailing slash /). The matching is case-insensitive.
*It then returns the <RK> value for this item as the "real" pagerank.
*Because of this, the tool has problems with URLs that are redirected. For example, www.espn.com is redirected to www.espn.go.com; and amazon.com is redirected to something like amazon.com/exec/obidos/subst/home/home.html. Even though Google recognizes this, the getrealrank() function will not.
E.g.:
$url = "www.google.com";
echo "The real PageRank of " . $url . " might be: <br />" . getrealrank($url);
*/

/*
This code is released unto the public domain
This script is originally from:
http://www.googlecommunity.com/scripts/google-pagerank.php
It is also hosted, and was modified slightly, by: http://www.searchengineengine.com
The architecture is:
getrank($url) function - The function called externally to get the PageRank
strord($url) function - Function called by getrank() to convert the url string into a numeric string
GoogleCH($numericstring) function - Function called by getrank() to get the checksum of the url
mix($a, $b, $c) function - Called by GoogleCH() during checksum calculation
zeroFill($a, $b) function - Called by mix() during mixing
*/

//header("Content-Type: text/plain; charset=utf-8"); //Uncommenting this makes the file downloadable rather than executable


define("GOOGLE_MAGIC", 0xE6359A60); //Define the named constant "GOOGLE_MAGIC"

//unsigned shift right

function zeroFill($a, $b) {
$z = hexdec(80000000);
if ($z & $a) {
$a = ($a>>1);
$a &= (~$z);
$a |= 0x40000000;
$a = ($a>>($b-1));
}
else {
$a = ($a>>$b);
}
return $a;
}

function mix($a, $b, $c) { //This function is used in the Google Checksum calculation
$a -= $b;
$a -= $c;
$a ^= (zeroFill($c,13));
$b -= $c;
$b -= $a;
$b ^= ($a<<8);
$c -= $a;
$c -= $b;
$c ^= (zeroFill($b,13));
$a -= $b;
$a -= $c;
$a ^= (zeroFill($c,12));
$b -= $c;
$b -= $a;
$b ^= ($a<<16);
$c -= $a;
$c -= $b;
$c ^= (zeroFill($b,5));
$a -= $b;
$a -= $c;
$a ^= (zeroFill($c,3));
$b -= $c;
$b -= $a;
$b ^= ($a<<10);
$c -= $a;
$c -= $b;
$c ^= (zeroFill($b,15));
return array($a,$b,$c);
}

function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) { //Calculate the Google Checksum for a given URL
if(is_null($length)) {
$length = sizeof($url);
}
$a = $b = 0x9E3779B9;
$c = $init;
$k = 0;
$len = $length;
while($len >= 12) {
$a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
$b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
$c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
$mix = mix($a,$b,$c);
$a = $mix[0];
$b = $mix[1];
$c = $mix[2];
$k += 12;
$len -= 12;
}
$c += $length;
switch($len) /* all the case statements fall through */
{
case 11: $c+=($url[$k+10]<<24);
case 10: $c+=($url[$k+9]<<16);
case 9 : $c+=($url[$k+8]<<8);
/* the first byte of c is reserved for the length */
case 8 : $b+=($url[$k+7]<<24);
case 7 : $b+=($url[$k+6]<<16);
case 6 : $b+=($url[$k+5]<<8);
case 5 : $b+=($url[$k+4]);
case 4 : $a+=($url[$k+3]<<24);
case 3 : $a+=($url[$k+2]<<16);
case 2 : $a+=($url[$k+1]<<8);
case 1 : $a+=($url[$k+0]);
/* case 0: nothing left to add */
}
$mix = mix($a,$b,$c);
return $mix[2];
}

function strord($string) { //converts a string into an array of integers containing the numeric value of the char
for($i=0;$i<strlen($string);$i++) {
$result[$i] = ord($string{$i});
}
return $result;
}

function getrank($url, $prefix="info:", $datacenter="www.google.com") { //This is the function used to get the PageRank value.
//If $prefix is "info:", then the Toolbar pagerank will be returned.
//$datacenter sets the datacenter to get the results from. e.g., "www.google.com", "216.239.53.99", "66.102.11.99".

$url = $prefix.$url;
$ch = GoogleCH(strord($url)); //Get the Google checksum for $url using the GoogleCH function.
$file = "http://$datacenter/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url";
//To get the Crawl Date instead of the PageRank, change "&features=Rank" to "&features=Crawldate"
//To get detailed XML results, remove "&features=Rank"

$oldlevel = error_reporting(0); //Suppress error reporting temporarily.
$data = file($file);
error_reporting($oldlevel); //Restart error reporting.
if(!$data || preg_match("/(.*)\.(.*)/i", $url)==0) return "N/A"; //If the Google data is unavailable, or the URL is invalid, return "N/A".
//The preg_match check is a very basic url validator that only checks if the URL has a period in it.

$rankarray = explode (":", $data[2]); //There are two line breaks before the PageRank data on the Google page.
$rank = trim($rankarray[2]); //Trim whitespace and line breaks.
if($rank=="") return "N/A"; //Return N/A if no rank.
return $rank;
}

function getrealrank($url, $datacenter="www.google.com"){
$ch = GoogleCH(strord($url));
$array = xmltoarray("http://$datacenter/search?client=navclient-auto&ch=6$ch&q=$url");
$infoarray = $array['GSP'][0]['RES'][0]['R'];
$nonwwwurl = str_replace("www.", "", $url);
$urlpermutationsarray = array($url, "http://".$url, "http://www.".$url, $url."/", "http://".$url."/", "http://www.".$url."/", $nonwwwurl, "http://".$nonwwwurl, "http://www.".$nonwwwurl, $nonwwwurl."/", "http://".$nonwwwurl."/", "http://www.".$nonwwwurl."/");
for($i=0; $i<count($infoarray); $i++){
$urlU = $infoarray[$i]['U']; //U is the URL. UE is the 'clean' URL.
$urlrank = $infoarray[$i]['RK'];
foreach($urlpermutationsarray as $permutation){
if(strtolower($permutation)==strtolower($urlU)) return $urlrank; //Case insensitive match.
}
}

return "Unknown"; //If no matches found.
}

$url = "habrahabr.ru";
echo "PageRank of ".$url." is:<br />".getrank($url);


?>


Выводит: PageRank of habrahabr.ru is:
N/A



Спустя 2 часа, 46 минут, 40 секунд (9.10.2011 - 17:20) Игорь_Vasinsky написал(а):
Разгребай

   if(!$data || preg_match("/(.*)\.(.*)/i", $url)==0) return "N/A";            //If the Google data is unavailable, or the URL is invalid, return "N/A".
//The preg_match check is a very basic url validator that only checks if the URL has a period in it.

$rankarray = explode (":", $data[2]); //There are two line breaks before the PageRank data on the Google page.
$rank = trim($rankarray[2]); //Trim whitespace and line breaks.
if($rank=="") return "N/A"; //Return N/A if no rank.

Спустя 1 час, 22 минуты, 8 секунд (9.10.2011 - 18:42) tanya12345 написал(а):
Выяснила, что все скрипты по поиску pr, найденные в сети, не работали по следующей причине:
Друзья, ачиная с 06.10.2011 большинство сервисов и программ по оределению Google PR (PageRank) перестали выдавать корректные значения, заменив их на 0 или N/A.

Данная ситуация ни в коем случае не связана с "обнулением" или даже отменой Google своего рейтинга страниц (PageRank).

Причина такого поведения очень проста: Google заблокировал доступ к старому адресу, через который многие сервисы и программы проверяют PR.

Старый адрес проверки Google PR имел следующий вид: www.google.com/search?client=navclient-auto&ch=%CHECKSUM%&features=Rank&q=info:%URL%

Новый адрес, при обращении к которому Google выдает корректные значения PageRank, имеет следующий вид: toolbarqueries.google.com/tbr?features=Rank&sourceid=navclient-ff&client=navclient-auto-ff&am p;ch=%CHECKSUM%&q=info:%URL%


Данный код со старыми параметрами, пытаюсь изменить на новые - не работает. Помогите поменять на новые параметры и чтобы работало!!!!

<?php
define('GOOGLE_MAGIC', 0xE6359A60);

function _zeroFill($a, $b){
$z = hexdec(80000000);
if ($z & $a){
$a = ($a>>1);
$a &= (~$z);
$a |= 0x40000000;
$a = ($a>>($b-1));
}else
$a = ($a>>$b);
return $a;
}

function _mix($a,$b,$c){
$a -= $b; $a -= $c; $a ^= (_zeroFill($c,13));
$b -= $c; $b -= $a; $b ^= ($a<<8);
$c -= $a; $c -= $b; $c ^= (_zeroFill($b,13));
$a -= $b; $a -= $c; $a ^= (_zeroFill($c,12));
$b -= $c; $b -= $a; $b ^= ($a<<16);
$c -= $a; $c -= $b; $c ^= (_zeroFill($b,5));
$a -= $b; $a -= $c; $a ^= (_zeroFill($c,3));
$b -= $c; $b -= $a; $b ^= ($a<<10);
$c -= $a; $c -= $b; $c ^= (_zeroFill($b,15));
return array($a,$b,$c);
}

function _GoogleCH($url, $length=null, $init=GOOGLE_MAGIC){
if(is_null($length))
$length = sizeof($url);
$a = $b = 0x9E3779B9;
$c = $init;
$k = 0;
$len = $length;
while($len >= 12){
$a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
$b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
$c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
$_mix = _mix($a,$b,$c);
$a = $_mix[0]; $b = $_mix[1]; $c = $_mix[2];
$k += 12;
$len -= 12;
}
$c += $length;
switch($len){
case 11: $c+=($url[$k+10]<<24);
case 10: $c+=($url[$k+9]<<16);
case 9 : $c+=($url[$k+8]<<8);
case 8 : $b+=($url[$k+7]<<24);
case 7 : $b+=($url[$k+6]<<16);
case 6 : $b+=($url[$k+5]<<8);
case 5 : $b+=($url[$k+4]);
case 4 : $a+=($url[$k+3]<<24);
case 3 : $a+=($url[$k+2]<<16);
case 2 : $a+=($url[$k+1]<<8);
case 1 : $a+=($url[$k+0]);
}
$_mix = _mix($a,$b,$c);
return $_mix[2];
}

function _strord($string){
for($i=0;$i<strlen($string);$i++)
$result[$i] = ord($string{$i});
return $result;
}

function getPageRank($url){
$pagerank = -1;
$ch = "6"._GoogleCH(_strord("info:" . $url));
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if($fp){
$out = "GET /search?client=navclient-auto&ch=" . $ch . "&features=Rank&q=info:" . $url . " HTTP/1.1\r\n";
$out .= "Host: www.google.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)){
$data = fgets($fp, 128);
$pos = strpos($data, "Rank_");
if($pos === false){
}
else
$pagerank = substr($data, $pos + 9);
}
fclose($fp);
}
return $pagerank;
}
?>

Спустя 52 минуты, 46 секунд (9.10.2011 - 19:35) tanya12345 написал(а):
УРА! НАКОНЕЦ-ТО ПОЛУЧИЛСЯ СКРИПТ PAGERANK.
ВЫКЛАДЫВАЮ МАЛО КОМУ ПРИГОДИТСЯ:


<?php
/**
*
@link http://info.sectorit.net
* @version 2011-01-26
*/

/**
* Конвертируем строку в 32-bit
*
@param string $str
*
@param hex $check
*
@param hex $magic
*
@return integer
*/

function strToNum($str, $check, $magic)
{
$int32Unit = 4294967296; // 2^32

$length = strlen($str);
for ($i = 0; $i < $length; $i++) {
$check *= $magic;
/**
* Если выпадаем за граници инта (обычно +/- 2.15e+9 = 2^31), то
* получим undefined, читать ниже по ссылке:
*
http://www.php.net/manual/en/language.types.integer.php
* потому танцуем с бубном
*/

if ($check >= $int32Unit) {
$check = ($check - $int32Unit * (int) ($check / $int32Unit));
//if the check less than -2^31
$check = ($check < -2147483648) ? ($check + $int32Unit) : $check;
}
$check += ord($str{$i});
}
return $check;
}

/**
* Получаем хеш URL-а
*
@param string $string
*
@return integer
*/

function hashUrl($string)
{
$check1 = strToNum($string, 0x1505, 0x21);
$check2 = strToNum($string, 0, 0x1003F);

$check1 >>= 2;
$check1 = (($check1 >> 4) & 0x3FFFFC0 ) | ($check1 & 0x3F);
$check1 = (($check1 >> 4) & 0x3FFC00 ) | ($check1 & 0x3FF);
$check1 = (($check1 >> 4) & 0x3C000 ) | ($check1 & 0x3FFF);

$T1 = (((($check1 & 0x3C0) << 4) | ($check1 & 0x3C)) <<2 ) | ($check2 & 0xF0F );
$T2 = (((($check1 & 0xFFFFC000) << 4) | ($check1 & 0x3C00)) << 0xA) | ($check2 & 0xF0F0000 );

return ($T1 | $T2);
}

/**
* Получаем чексум URL-а
*
@param integer $Hashnum хеш URL-а
*
@return integer
*/

function checkHash($hashNum)
{
$checkByte = 0;
$flag = 0;

$hashStr = sprintf('%u', $hashNum) ;
$length = strlen($hashStr);

for ($i = $length - 1; $i >= 0; $i --) {
$re = $hashStr{$i};
if (1 === ($flag % 2)) {
$re += $re;
$re = (int)($re / 10) + ($re % 10);
}
$checkByte += $re;
$flag ++;
}

$checkByte %= 10;
if (0 !== $checkByte) {
$checkByte = 10 - $checkByte;
if (1 === ($flag % 2) ) {
if (1 === ($checkByte % 2)) {
$checkByte += 9;
}
$checkByte >>= 1;
}
}


return '7' . $checkByte . $hashStr;
}

/**
* Получаем PR с одного из сайтов гугла "закосив" под мозиллу
*
@param string $url URL страницы
*/

function getPR($url)
{
if ( ! preg_match('/^(http:\/\/)(.*)/i', $url)) {
$url = 'http://' . $url;
}
$googlehost = 'toolbarqueries.google.com';
$googleua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5';

$ch = checkHash(hashUrl($url));
/**
* Используя сокеты, вероятность бана снижается до 0,
* темболее что едим только 30 первых символов ;)
*/

$fp = fsockopen($googlehost, 80, $errno, $errstr, 30);
if ($fp) {
$out = "GET /tbr?client=navclient-auto&ch=$ch&features=Rank&q=info:$url HTTP/1.1\r\n";
$out .= "User-Agent: $googleua\r\n";
$out .= "Host: $googlehost\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);

while ( ! feof($fp)) {
$data = fgets($fp, 128);
// ПР идёт в строке Rank_1:1:Х где Х наш ПР
$pos = strpos($data, "Rank_");
if($pos === false){} else{
fclose($fp);
$pr=substr($data, $pos + 9);
$pr=trim($pr);
$pr=str_replace("\n",'',$pr);
return $pr ? $pr : '0';
}
}

fclose($fp);
}
}




Спустя 1 час, 37 минут, 51 секунда (9.10.2011 - 21:13) Игорь_Vasinsky написал(а):
Цитата
ВЫКЛАДЫВАЮ МАЛО КОМУ ПРИГОДИТСЯ:

вот за это молодец!
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.