package com.sodao;
/// <summary>
/// Google PageRank的Checksum算法。
///
///
///
/// </summary>
public class CheckSum {
public CheckSum()
{
}
long GOOGLE_MAGIC = 0xE6359A60l;
private long zeroFill(long a, long b)
{
long z = 0x80000000l;
if ((z & a)!=0)
{
a = (a >> 1);
a &= (~z);
a |= 0x40000000;
a = (a >> (b - 1));
}
else
{
a = (a >> b);
}
return a;
}
private long[] mix(long a, long b, long c)
{
a -= b;
a &= 0xFFFFFFFFl;
a -= c;
a &= 0xFFFFFFFFl;
a ^= (zeroFill(c, 13));
b -= c;
b &= 0xFFFFFFFFl;
b -= a;
b &= 0xFFFFFFFFl;
b ^= (a << 8);
b &= 0xFFFFFFFFl;
c -= a;
c &= 0xFFFFFFFFl;
c -= b;
c &= 0xFFFFFFFFl;
c ^= (zeroFill(b, 13));
a -= b;
a &= 0xFFFFFFFFl;
a -= c;
a &= 0xFFFFFFFFl;
a ^= (zeroFill(c, 12));
b -= c;
b &= 0xFFFFFFFFl;
b -= a;
b &= 0xFFFFFFFFl;
b ^= (a << 16);
b &= 0xFFFFFFFFl;
c -= a;
c &= 0xFFFFFFFFl;
c -= b;
c &= 0xFFFFFFFFl;
c ^= (zeroFill(b, 5));
a -= b;
a &= 0xFFFFFFFFl;
a -= c;
a &= 0xFFFFFFFFl;
a ^= (zeroFill(c, 3));
b -= c;
b &= 0xFFFFFFFFl;
b -= a;
b &= 0xFFFFFFFFl;
b ^= (a << 10);
b &= 0xFFFFFFFFl;
c -= a;
c &= 0xFFFFFFFFl;
c -= b;
c &= 0xFFFFFFFFl;
c ^= (zeroFill(b, 15));
// a &= 0xFFFFFFFFl;
// b &= 0xFFFFFFFFl;
// c &= 0xFFFFFFFFl;
// System.out.println("a:@" + a);
// System.out.println("b:@" + b);
// System.out.println("c:@" + c);
long[] ret = { a, b, c };
return(ret) ;
}
private long GoogleCH(long[] url, int length, long init)
{
if (length == 0)
{
length = (int)url.length;
}
long a, b;
a = b = 0x9E3779B9l;
long c = init;
int k = 0;
int len = length;
long[] m_mix = new long[3];
// System.out.println("a:"+a);
// System.out.println("b:"+b);
// System.out.println("c:"+c);
while (len >= 12)
{
a += url[k + 0];
//System.out.println("a1:"+a);
a += ((long)url[k + 1]) << 8 ;
//System.out.println("a2:"+a);
a += (((long)url[k + 2]) << 16);
//System.out.println("a3:"+a);
a += (((long)url[k + 3]) << 24);
//System.out.println("a4:"+a);
a &= 0xFFFFFFFFl;
b += (url[k + 4] + (long)(url[k + 5] << 8) + (long)(url[k + 6] << 16) + (long)(url[k + 7] << 24));
c += (url[k + 8] + (long)(url[k + 9] << 8) + (long)(url[k + 10] << 16) + (long)(url[k + 11] << 24));
b &= 0xFFFFFFFFl;
c &= 0xFFFFFFFFl;
// System.out.println("a:"+a);
// System.out.println("b:"+b);
// System.out.println("c:"+c);
m_mix = mix(a, b, c);
a = m_mix[0]; b = m_mix[1]; c = m_mix[2];
// a &= 0xFFFFFFFFl;
// b &= 0xFFFFFFFFl;
// c &= 0xFFFFFFFFl;
k += 12;
len -= 12;
}
//System.out.println("a:"+a);
//System.out.println("b:"+b);
//System.out.println("c:"+c);
c += length;
//System.out.println("len:"+len);
switch (len) /* all the case statements fall through */
{
case 11:
{
c += (long)(url[k + 10] << 24);
c &= 0xFFFFFFFFl;
c += (long)(url[k + 9] << 16);
c &= 0xFFFFFFFFl;
c += (long)(url[k + 8] << 8);
c &= 0xFFFFFFFFl;
b += (long)(url[k + 7] << 24);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 6] << 16);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 5] << 8);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 4]);
b &= 0xFFFFFFFFl;
a += (long)(url[k + 3] << 24);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
case 10:
{
c += (long)(url[k + 9] << 16);
c &= 0xFFFFFFFFl;
c += (long)(url[k + 8] << 8);
c &= 0xFFFFFFFFl;
b += (long)(url[k + 7] << 24);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 6] << 16);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 5] << 8);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 4]);
b &= 0xFFFFFFFFl;
a += (long)(url[k + 3] << 24);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
case 9:
{
c += (long)(url[k + 8] << 8);
c &= 0xFFFFFFFFl;
b += (long)(url[k + 7] << 24);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 6] << 16);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 5] << 8);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 4]);
b &= 0xFFFFFFFFl;
a += (long)(url[k + 3] << 24);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
/* the first byte of c is reserved for the length */
case 8:
{
b += (long)(url[k + 7] << 24);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 6] << 16);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 5] << 8);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 4]);
b &= 0xFFFFFFFFl;
a += (long)(url[k + 3] << 24);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
case 7:
{
b += (long)(url[k + 6] << 16);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 5] << 8);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 4]);
b &= 0xFFFFFFFFl;
a += (long)(url[k + 3] << 24);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
case 6:
{
b += (long)(url[k + 5] << 8);
b &= 0xFFFFFFFFl;
b += (long)(url[k + 4]);
b &= 0xFFFFFFFFl;
a += (long)(url[k + 3] << 24);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
case 5:
{
b += (long)(url[k + 4]);
b &= 0xFFFFFFFFl;
a += (long)(url[k + 3] << 24);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
case 4:
{
a += (long)(url[k + 3] << 24);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
case 3:
{
a += (long)(url[k + 2] << 16);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
//System.out.println("a:!!!!"+a);
break;
}
case 2:
{
a += (long)(url[k + 1] << 8);
a &= 0xFFFFFFFFl;
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
case 1:
{
a += (long)(url[k + 0]);
a &= 0xFFFFFFFFl;
break;
}
/* case 0: nothing left to add */
}
m_mix = mix(a, b, c);
/*-------------------------------------------- report the result */
return m_mix[2];
}
private long GoogleCH(String url, int length)
{
long[] m_urlint = new long[url.length()];
for (int i = 0; i < url.length(); i++)
{
m_urlint[i] = url.charAt(i);
//System.out.println("m_urlint[i]:"+m_urlint[i]);
}
return GoogleCH(m_urlint, length, GOOGLE_MAGIC);
}
private long GoogleCH(String sURL)
{
return GoogleCH(sURL, 0);
}
private long GoogleCH(long[] url, int length)
{
return GoogleCH(url, length, GOOGLE_MAGIC);
}
private long[] c32to8bit(long[] arr32)
{
long[] arr8 = new long[arr32.length * 4 + 3];
for (int i = 0; i < arr32.length; i++)
{
for (int bitOrder = i * 4; bitOrder <= i * 4 + 3; bitOrder++)
{
arr8[bitOrder] = arr32[i] & 255;
arr32[i] = zeroFill(arr32[i], 8);
}
}
return arr8;
}
//新算法,ToolBar 版本>>=2.0.114
public String CalculateChecksum(String sURL)
{
long ch = GoogleCH("info:" + sURL);
//System.out.println("ch:"+ch);
ch = (((ch / 7) << 2) | (((int)(ch % 13)) & 7));
//System.out.println("ch2:"+ch);
long[] prbuf = new long[20];
prbuf[0] = ch;
for (int i = 1; i < 20; i++)
{
prbuf[i] = prbuf[i - 1] - 9;
//System.out.println("prbuf[i]:"+prbuf[i]);
}
ch = GoogleCH(c32to8bit(prbuf), 80);
return "6"+ch;
}
//老算法,ToolBar 版本<2.0.114
/*public String CalculateChecksumOld(String sURL)
{
int ch = GoogleCH("info:" + sURL);
String CalculateChecksum = "6" + ((ch));
return CalculateChecksum;
}*/
}
package com.sodao;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class PageRank {
/*
* public static void main(String[] args)throws Exception { String url =
* "http://www.safe-drive.com/";
*
* System.out.println(getPageRank(url)); }
*/
public static String getPageRank(String url) {
String responseFromServer = "";
CheckSum cs = new CheckSum();
String s = cs.CalculateChecksum(url);
try {
URL openurl = new URL(
"http://www.google.cn/search?client=navclient-auto&features=Rank:&q=info:"
+ url + "&ch=" + s);
URLConnection HttpWReq = openurl.openConnection();
HttpWReq.setRequestProperty("Accept", "*/*");
HttpWReq.setRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)");
BufferedReader r = new BufferedReader(new InputStreamReader(
HttpWReq.getInputStream()));
while ((s = r.readLine()) != null) {
// System.out.println(s);
responseFromServer = s;
}
r.close();
} catch (Exception e) {
e.printStackTrace();
}
String[] sp = responseFromServer.split(":");
String lbValue = null;
if (sp.length == 3)
lbValue = "查询成功! PR = " + sp[2].toString();
else
lbValue = "查询失败!";
return (lbValue);
}
public static void main(String[] args) {
System.out.println(new PageRank().getPageRank("http://sports.sina.com.cn"));
}
}
分享到:
相关推荐
在本文中,我们将深入探讨如何使用PHP编程语言来获取Google PageRank(PR值)的详细步骤,以及关于Google PR值的一些基本概念。首先,我们来看看什么是Google PR值。 Google PageRank是Google搜索引擎早期用于评估...
5. **显示结果**:最后,将获取到的PR值以适当的方式展示给用户,例如在控制台输出,或者在GUI界面中显示。 值得注意的是,由于Google已经不再更新和公开PR值,这样的程序可能只能获取到历史数据或者近似的PR估算值...
获取到的PR值可以存储在数据库或文件中,以便后续分析。 10. **测试**: 编写单元测试和集成测试,确保代码的正确性和稳定性。 虽然目前无法直接获取到Google PR值,但这些技术知识对于理解网络爬虫、HTML解析...
【Google PR值查询代码】是用于获取一个网页的PageRank值的程序代码。这段代码主要由以下几个部分组成: 1. `zeroFill` 函数:这个函数用于将一个数字右移指定位数,并在最左侧填充零。在混合函数中用于调整位运算...
总的来说,这款VB编写的Google PR值查询工具展示了VB在Web数据获取、用户界面设计以及程序扩展性方面的应用。通过学习和分析这个工具的源码,开发者可以提升自己的网络编程能力,理解如何与Web服务进行交互,以及...
PR值查询源码是用于开发工具或网站,帮助用户获取网页的PR值信息的代码。 PR值的计算基于网页之间的链接关系,一个被很多高质量网页链接的页面通常会获得较高的PR值。Google通过复杂的算法计算每个网页的PR值,并用...
MyIPStatusBar插件的PR值查询功能使得用户无需离开当前浏览页面,就能即时获取到网站的PR信息,这对于评估网站的搜索引擎优化状况至关重要。 除了PR值,MyIPStatusBar还提供了百度和Google的收录情况查询。百度是...
- **获取权威链接**:从权威和相关性强的网站获得链接,这将大大提升PR值。 - **链接质量胜于数量**:一个高质量的链接往往比大量低质量链接更有价值。 - **锚文本**:外部链接的锚文本中包含关键词,可以提升...
标题中的“谷歌计算PR值的dll”指的是Google的PageRank算法的一种实现,它是一个动态链接库(DLL)文件,用于计算网页的PageRank值。PageRank是谷歌搜索引擎排名算法的重要组成部分,由谷歌创始人拉里·佩奇(Larry ...
4. **结果显示**:获取到PR值后,程序将结果显示在网页上,通常包括PR值的数字以及可能的等级图标。 5. **错误处理**:对于无效或不存在的URL,程序应有适当的错误处理机制,向用户提供友好的提示信息。 **项目...
1. 输入网址:用户可以直接输入待查询网页的URL,工具会自动向Google服务器发送请求,获取该页面的PR值。 2. 批量查询:对于SEO工作,可能需要查询多个网站或页面的PR值,工具提供批量导入和查询功能,可以一次性...
这种方法既能增加网站的曝光率,又能获取高质量的外部链接,对于提高PR值大有裨益。 ### 方法三:参与知名论坛 注册并活跃在相关行业的知名论坛,如天涯、猫扑等,通过参与讨论、分享知识,逐渐提升个人信誉度,...
首先,了解PageRank的工作机制对掌握如何通过PHP获取PR值至关重要。PageRank算法基于网页间相互链接的结构计算网页的重要性,网页获得的外部链接越多,质量越高,其PageRank值通常也会越高。 在PHP中,通常使用file...
本文将深入探讨“IE底部SEO显示”这一主题,包括PR值(PageRank)和Alexa排名,以及如何在IE浏览器中查看这些信息。 首先,PR值是由谷歌公司发明的一种衡量网页重要性的算法。PR值从0到10,10为最高,它基于网页...
2. **HTTP请求**:查询PR值需要向Google服务器发送HTTP请求,获取PR信息。这可能使用到PHP的`file_get_contents()`、`curl`库或者其他HTTP客户端库,如Guzzle。请求的目标通常是Google的toolbar_data.txt文件,其中...
此系统能够方便地获取多个网站的PR值,有助于分析网站的权重分布和优化策略。 ASP(Active Server Pages)是微软开发的一种服务器端脚本环境,用于生成动态网页。通过ASP,开发者可以使用VBScript或JScript等语言...
PR值,全称PageRank,是Google早期用于衡量一个网页重要性的一个算法,它通过分析网页之间的链接关系来评估其价值。高PR值的外链资源对于提升网站权重和搜索引擎排名具有显著的影响。因此,"外链资源 高PR值 别错过...
这个工具允许用户输入一个网站的URL,然后通过与Google服务器交互获取该网站的PR值。 在VB中实现这个功能,主要涉及到以下几个关键知识点: 1. **网络请求**:首先,VB需要能够向Google的服务器发送HTTP请求,获取...
在这个实例中,PHP将用于接收用户的URL输入,然后向Google的API或公共数据源发起请求,获取对应PR值。 在实际的代码实现中,可能会包含以下几个关键部分: 1. **用户界面**:通常是一个简单的HTML表单,用户输入要...
最新获取谷歌PR值的函数,绝对可用,windows/linux皆可。 最新的查询谷歌PR值函数(接口),CH值最新算法,绝对准确。 使用方法: include 'googlepr.php'; echo getPR('http://yanglu.org'); ?> 显示结果...