欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

JAVA获得网站Google PR,java获得googlepr,/** * List o

来源: javaer 分享于  点击 19931 次 点评:278

JAVA获得网站Google PR,java获得googlepr,/** * List o


/** * 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.51youlian.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.51youlian.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");}//该片段来自于http://byrx.net
相关栏目:

用户点评