谷歌网页排名的Java API [英] Google page rank java api

查看:192
本文介绍了谷歌网页排名的Java API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要得到的谷歌网页排名为给定域。

I want to get the google page rank for the given domain.

我用下面的code API谷歌code,以获得pagerank.I得到了网页排名before.Today当我试图在运行相同的文件我得到了一些问题和canot得到正确的页面军衔。

I used the following code google api code to get the pagerank.I got the page rank before.Today when i tried the to run the same file i got the some issues and canot get the correct page rank.

import java.net.URLConnection;
import java.net.URL;
import java.io.InputStream;

/**
 * <b>PageRankService provides simple API to Google PageRank Technology</b>
 * <br>
 * PageRankService queries google toolbar webservice and returns a
 * google page rank retrieved from one of the next datacenters on the list.
 * <br>toolbarqueries.google.com
 * <br>64.233.161.100
 * <br>64.233.161.101
 * <br>64.233.177.17
 * <br>64.233.183.91
 * <br>64.233.185.19
 * <br>64.233.189.44
 * <br>66.102.1.103
 * <br>66.102.9.115
 * <br>66.249.81.101
 * <br>66.249.89.83
 * <br>66.249.91.99
 * <br>66.249.93.190
 * <br>72.14.203.107
 * <br>72.14.205.113
 * <br>72.14.255.107
 */
public class PageRankService {

    static private int dataCenterIdx = 0;

    /**
     * List of available google datacenter IPs and addresses
     */
    static final public String [] GOOGLE_PR_DATACENTER_IPS = new String[]{
                "64.233.161.100",
                "64.233.161.101",
                "64.233.177.17",
                "64.233.183.91",
                "64.233.185.19",
                "64.233.189.44",
                "66.102.1.103",
                "66.102.9.115",
                "66.249.81.101",
                "66.249.89.83",
                "66.249.91.99",
                "66.249.93.190",
                "72.14.203.107",
                "72.14.205.113",
                "72.14.255.107",
                "toolbarqueries.google.com",
                };

    /**
     * Default constructor
     */
    public PageRankService() {

    }

    /**
     * Must receive a domain in form of: "http://www.domain.com"
     * @param domain - (String)
     * @return PR rating (int) or -1 if unavailable or internal error happened.
     */
    public int getPR(String domain) {

        int result = -1;
        JenkinsHash jHash = new JenkinsHash();

        String googlePrResult = "";

        long hash = jHash.hash(("info:" + domain).getBytes());

        String url = "http://"+GOOGLE_PR_DATACENTER_IPS[dataCenterIdx]+"/search?client=navclient-auto&hl=en&"+
                "ch=6"+hash+"&ie=UTF-8&oe=UTF-8&features=Rank&q=info:" + domain;

        try {
            URLConnection con = new URL(url).openConnection();
            InputStream is = con.getInputStream();
            byte [] buff = new byte[1024];
            int read = is.read(buff);
            while (read > 0) {
                googlePrResult = new String(buff, 0, read);
                read = is.read(buff);
            }
            googlePrResult = googlePrResult.split(":")[2].trim();
            result = new Long(googlePrResult).intValue();
        } catch (Exception e) {
            e.printStackTrace();
        }

        dataCenterIdx++;
        if (dataCenterIdx == GOOGLE_PR_DATACENTER_IPS.length) {
            dataCenterIdx = 0;
        }

        return result;

    }

    public static void main(String [] args) {
        long start = System.currentTimeMillis();
        PageRankService prService = new PageRankService();
        String domain = "http://www.gmail.com";
        if (args.length > 0) {
            domain = args[0];
        }
        System.out.println("Checking " + domain);
        System.out.println("Google PageRank: " + prService.getPR(domain));
        System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms");
    }
}

但今天,我不能让网页排名。我正在以下错误:

But today i cant get the page rank .I am getting the following error:

Checking http://www.google.com
Google PageRank: -1
java.io.IOException: Server returned HTTP response code: 504 for URL: http://64.233.161.100/search?client=navclient-auto&hl=en&ch=63513778613&ie=UTF-8&oe=UTF-8&features=Rank&q=info:http://www.google.com
Took: 179711ms
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1625)
    at PageRankService.getPR(PageRankService.java:82)
    at PageRankService.main(PageRankService.java:112)
BUILD SUCCESSFUL (total time: 3 minutes 0 seconds)

我要去的地方错了?

Where i am going wrong?

推荐答案

我不是专家,但尝试使用的 http://tool​​barqueries.google.com/tbr ?而不是/搜​​索

I'm not an expert, but try to use http://toolbarqueries.google.com/tbr? instead of /search

这篇关于谷歌网页排名的Java API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆