如何在页面上 获取Google 的 PageRank 的值

来源:互联网 发布:js正则匹配空格 编辑:程序博客网 时间:2024/04/26 07:31
The Google Pagerank Checksum Calculator
DEMO:
http://alex.vort-x.net/google/
Source:

CODE
  1. <?php
  2. /*
  3.    This code is released unto the public domain
  4. */
  5. header("Content-Type: text/plain; charset=utf-8");
  6. define('GOOGLE_MAGIC', 0xE6359A60);
  7. //unsigned shift right
  8. function zeroFill($a, $b)
  9. {
  10.    $z = hexdec(80000000);
  11.        if ($z & $a)
  12.        {
  13.            $a = ($a>>1);
  14.            $a &= (~$z);
  15.            $a |= 0x40000000;
  16.            $a = ($a>>($b-1));
  17.        }
  18.        else
  19.        {
  20.            $a = ($a>>$b);
  21.        }
  22.        return $a;
  23. }
  24. function mix($a,$b,$c) {
  25.  $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
  26.  $b -= $c; $b -= $a; $b ^= ($a<<8);
  27.  $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
  28.  $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
  29.  $b -= $c; $b -= $a; $b ^= ($a<<16);
  30.  $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
  31.  $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));  
  32.  $b -= $c; $b -= $a; $b ^= ($a<<10);
  33.  $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
  34.  return array($a,$b,$c);
  35. }
  36. function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
  37.    if(is_null($length)) {
  38.        $length = sizeof($url);
  39.    }
  40.    $a = $b = 0x9E3779B9;
  41.    $c = $init;
  42.    $k = 0;
  43.    $len = $length;
  44.    while($len >= 12) {
  45.        $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
  46.        $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
  47.        $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
  48.        $mix = mix($a,$b,$c);
  49.        $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
  50.        $k += 12;
  51.        $len -= 12;
  52.    }
  53.    $c += $length;
  54.    switch($len)              /* all the case statements fall through */
  55.    {
  56.        case 11: $c+=($url[$k+10]<<24);
  57.        case 10: $c+=($url[$k+9]<<16);
  58.        case 9 : $c+=($url[$k+8]<<8);
  59.          /* the first byte of c is reserved for the length */
  60.        case 8 : $b+=($url[$k+7]<<24);
  61.        case 7 : $b+=($url[$k+6]<<16);
  62.        case 6 : $b+=($url[$k+5]<<8);
  63.        case 5 : $b+=($url[$k+4]);
  64.        case 4 : $a+=($url[$k+3]<<24);
  65.        case 3 : $a+=($url[$k+2]<<16);
  66.        case 2 : $a+=($url[$k+1]<<8);
  67.        case 1 : $a+=($url[$k+0]);
  68.         /* case 0: nothing left to add */
  69.    }
  70.    $mix = mix($a,$b,$c);
  71.    /*-------------------------------------------- report the result */
  72.    return $mix[2];
  73. }
  74. //converts a string into an array of integers containing the numeric value of the char
  75. function strord($string) {
  76.    for($i=0;$i<strlen($string);$i++) {
  77.        $result[$i] = ord($string{$i});
  78.    }
  79.    return $result;
  80. }
  81. // http://www.example.com/ - Checksum: 6540747202
  82. $url = 'info:'.$_GET['url'];
  83. $ch = GoogleCH(strord($url));
  84. $url='info:'.urlencode($_GET['url']);
  85. $curl = curl_init("http://www.google.com/search?client=navclient-auto&ch=6$ch&ie=UTF-8&oe=UTF-8&features=Rank&q=$url");
  86. curl_setopt ($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; GoogleToolbar 2.0.110-big; Windows 2000 5.0)");
  87. curl_exec($curl);
  88. ?>


Format:
http://www.google.com/search?client=navcli...ttp://bbs.z4.cn

Related link:
http://www.mobileread.com/forums/sh...p?threadid=1670
short :http://alex.vort-x.net/google/googlehash-source.php
readable :http://alex.vort-x.net/google/googl...able-source.php
http://forums.seochat.com/t12316/s.html
http://www.top25web.com/pagerank.php
http://www.abakus-internet-marketin...rts/seotest.htm
http://www.zenitram.th4y.com/pagerank/?url=bbs.z4.cn
http://cgi.ebay.com/ws/eBayISAPI.dl...ssPageName=WDVW
also:
http://pagerank-checksum.homelinux.com/

http://www.zenitram.th4y.com/pagerank/?url=bbs.z4.cn
Source:

CODE
  1. <?php
  2. // Google PageRank Calculator function by ZeNiTRaM - version 0.1
  3. // Licensed under the GPL License
  4. // eMail me at zenitram [AT] dubmail.net
  5. // Uses code from The Google Checksum Calculator, by Alex Stapleton, Andy Doctorow, Vijay "Cyberax" Bhatter, and a few others, licensed under the public domain (http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) and XMLize.php by Hans Anderson (http://www.hansanderson.com/php/xml/).
  6. // Use: $pagerank = GetPagerank("http://www.google.es");
  7. // GetPagerank returns a STRING with the Pagerank number directly from Google
  8. //    S    P    A    N    I    S    H-----------------------------------------------------------------------------------
  9. // Calculadora Google Pagerank por ZeNiTRaM - version 0.1
  10. // Licenciado bajo la licencia GPL.
  11. // Contacta conmigo en zenitram [AT] dubmail.net
  12. // Usa codigo de The Google Checksum Calculator, por Alex Stapleton, Andy Doctorow, Vijay "Cyberax" Bhatter, y unos cuantos otros mas, licenciado bajo dominio publico (http://www.mobileread.com/forums/showpost.php?p=7769&postcount=87) y XMLize.php por Hans Anderson (http://www.hansanderson.com/php/xml/).
  13. /*
  14. Changelog
  15. 0.1:    Started counting versions and tidied all the code. Maybe I will add some new functions to get more information from Google.
  16.    He empezado a contar versiones y limpiado un poco todo el codigo. Quizas a&ntilde;ada nuevas funciones para conseguir mas informacion de Google.
  17. */
  18. // Function GetPagerank
  19. function GetPagerank($urlo) {
  20. define('GOOGLE_MAGIC', 0xE6359A60);
  21. $url = 'info:'.$urlo;
  22. $ch = GoogleCH(strord($url));
  23. $chf = "6$ch";
  24. $file = file("http://www.google.com/search?client=navclient-auto&ch=$chf&q=$url");
  25. $file_str = implode("", $file);
  26. $xml = xmlize($file_str);
  27. $pr = $xml["GSP"]["#"]["RES"][0]["#"]["R"][0]["#"]["RK"][0]["#"];
  28. if(!$pr) $pr = 0;
  29. return $pr;
  30. }
  31. //Starts code from XMLize.php
  32. function xmlize($data, $WHITE=1) {
  33.    $data = trim($data);
  34.    $vals = $index = $array = array();
  35.    $parser = xml_parser_create();
  36.    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  37.    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $WHITE);
  38.    if ( !xml_parse_into_struct($parser, $data, $vals, $index) )
  39.    {
  40.    die(sprintf("XML error: %s at line %d",
  41.                    xml_error_string(xml_get_error_code($parser)),
  42.                    xml_get_current_line_number($parser)));
  43.    }
  44.    xml_parser_free($parser);
  45.    $i = 0;
  46.    $tagname = $vals[$i]['tag'];
  47.    if ( isset ($vals[$i]['attributes'] ) )
  48.    {
  49.        $array[$tagname]['@'] = $vals[$i]['attributes'];
  50.    } else {
  51.        $array[$tagname]['@'] = array();
  52.    }
  53.    $array[$tagname]["#"] = xml_depth($vals, $i);
  54.    return $array;
  55. }
  56. /*
  57. *
  58. * You don't need to do anything with this function, it's called by
  59. * xmlize.  It's a recursive function, calling itself as it goes deeper
  60. * into the xml levels.  If you make any improvements, please let me know.
  61. *
  62. *
  63. */
  64. function xml_depth($vals, &$i) {
  65.    $children = array();
  66.    if ( isset($vals[$i]['value']) )
  67.    {
  68.        array_push($children, $vals[$i]['value']);
  69.    }
  70.    while (++$i < count($vals)) {
  71.        switch ($vals[$i]['type']) {
  72.           case 'open':
  73.                if ( isset ( $vals[$i]['tag'] ) )
  74.                {
  75.                    $tagname = $vals[$i]['tag'];
  76.                } else {
  77.                    $tagname = '';
  78.                }
  79.                if ( isset ( $children[$tagname] ) )
  80.                {
  81.                    $size = sizeof($children[$tagname]);
  82.                } else {
  83.                    $size = 0;
  84.                }
  85.                if ( isset ( $vals[$i]['attributes'] ) ) {
  86.                    $children[$tagname][$size]['@'] = $vals[$i]["attributes"];
  87.                }
  88.                $children[$tagname][$size]['#'] = xml_depth($vals, $i);
  89.            break;
  90.            case 'cdata':
  91.                array_push($children, $vals[$i]['value']);
  92.            break;
  93.            case 'complete':
  94.                $tagname = $vals[$i]['tag'];
  95.                if( isset ($children[$tagname]) )
  96.                {
  97.                    $size = sizeof($children[$tagname]);
  98.                } else {
  99.                    $size = 0;
  100.                }
  101.                if( isset ( $vals[$i]['value'] ) )
  102.                {
  103.                    $children[$tagname][$size]["#"] = $vals[$i]['value'];
  104.                } else {
  105.                    $children[$tagname][$size]["#"] = '';
  106.                }
  107.                if ( isset ($vals[$i]['attributes']) ) {
  108.                    $children[$tagname][$size]['@']
  109.                                             = $vals[$i]['attributes'];
  110.                }            
  111.            break;
  112.            case 'close':
  113.                return $children;
  114.            break;
  115.        }
  116.    }
  117.    return $children;
  118. }
  119. /* function by acebone@f2s.com, a HUGE help!
  120. *
  121. * this helps you understand the structure of the array xmlize() outputs
  122. *
  123. * usage:
  124. * traverse_xmlize($xml, 'xml_');
  125. * print '<pre>' . implode("", $traverse_array . '</pre>';
  126. *
  127. *
  128. */
  129. function traverse_xmlize($array, $arrName = "array", $level = 0) {
  130.    foreach($array as $key=>$val)
  131.    {
  132.        if ( is_array($val) )
  133.        {
  134.            traverse_xmlize($val, $arrName . "[" . $key . "]", $level + 1);
  135.        } else {
  136.            $GLOBALS['traverse_array'][] = '$' . $arrName . '[' . $key . '] = "' . $val . "/"/n";
  137.        }
  138.    }
  139.    return 1;
  140. }
  141. //Ends code from XMLize.php
  142. //Starts code from The Google Checksum Calculator
  143. //unsigned shift right
  144. function zeroFill($a, $b)
  145. {
  146.    $z = hexdec(80000000);
  147.        if ($z & $a)
  148.        {
  149.            $a = ($a>>1);
  150.            $a &= (~$z);
  151.            $a |= 0x40000000;
  152.            $a = ($a>>($b-1));
  153.        }
  154.        else
  155.        {
  156.            $a = ($a>>$b);
  157.        }
  158.        return $a;
  159. }
  160. function mix($a,$b,$c) {
  161.  $a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
  162.  $b -= $c; $b -= $a; $b ^= ($a<<8);
  163.  $c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
  164.  $a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
  165.  $b -= $c; $b -= $a; $b ^= ($a<<16);
  166.  $c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
  167.  $a -= $b; $a -= $c; $a ^= (zeroFill($c,3));  
  168.  $b -= $c; $b -= $a; $b ^= ($a<<10);
  169.  $c -= $a; $c -= $b; $c ^= (zeroFill($b,15));
  170.  return array($a,$b,$c);
  171. }
  172. function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
  173.    if(is_null($length)) {
  174.        $length = sizeof($url);
  175.    }
  176.    $a = $b = 0x9E3779B9;
  177.    $c = $init;
  178.    $k = 0;
  179.    $len = $length;
  180.    while($len >= 12) {
  181.        $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
  182.        $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
  183.        $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
  184.        $mix = mix($a,$b,$c);
  185.        $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
  186.        $k += 12;
  187.        $len -= 12;
  188.    }
  189.    $c += $length;
  190.    switch($len)              /* all the case statements fall through */
  191.    {
  192.        case 11: $c+=($url[$k+10]<<24);
  193.        case 10: $c+=($url[$k+9]<<16);
  194.        case 9 : $c+=($url[$k+8]<<8);
  195.          /* the first byte of c is reserved for the length */
  196.        case 8 : $b+=($url[$k+7]<<24);
  197.        case 7 : $b+=($url[$k+6]<<16);
  198.        case 6 : $b+=($url[$k+5]<<8);
  199.        case 5 : $b+=($url[$k+4]);
  200.        case 4 : $a+=($url[$k+3]<<24);
  201.        case 3 : $a+=($url[$k+2]<<16);
  202.        case 2 : $a+=($url[$k+1]<<8);
  203.        case 1 : $a+=($url[$k+0]);
  204.         /* case 0: nothing left to add */
  205.    }
  206.    $mix = mix($a,$b,$c);
  207.    /*-------------------------------------------- report the result */
  208.    return $mix[2];
  209. }
  210. //converts a string into an array of integers containing the numeric value of the char
  211. function strord($string) {
  212.    for($i=0;$i<strlen($string);$i++) {
  213.        $result[$i] = ord($string{$i});
  214.    }
  215.    return $result;
  216. }
  217. //End code from The Google Checksum Calculator
  218. ?>


http://www.seroundtable.com/
http://www.seobook.com/

原创粉丝点击