zoukankan      html  css  js  c++  java
  • C#获取google PageRank

    using System;
    using System.Net;
    namespace BLL
    {
        /// <summary>
        /// 下载信息url的html内容的类
        /// </summary>
        public class Net
        {
            public static string GetHtml(string url)
            {
                string html = "";
                WebClient wc = new WebClient();
                try { html = wc.DownloadString(url); }
                catch { }
                return html;
            }
        }
        /// <summary>
        /// 获取google pageran的类
        /// </summary>
        public class GooglePR
        {
            public static string GetPageRank(string strUrl)
            {
                string sURL = "http://toolbarqueries.google.com/search?client=navclient-auto&ch=" + GetPR(strUrl) + "&ie=UTF-8&oe=UTF-8&features=Rank&q=info:" + System.Web.HttpUtility.UrlEncode(strUrl);
                string result = Net.GetHtml(sURL);
                if (result != null)
                {
                    result = result.Trim();
                    if (result.IndexOf(':') > 0)
                    {
                        string[] pr = result.Split(':');
                        if (pr.Length == 3) return pr[2].ToString();

                    }
                }
                return "0";
            }

            private static string GetPR(string url)
            {
                url = "info:" + url;
                string ch = GoogleCH(str_asc(url)).ToString();
                ch = "6" + ch;
                return ch;
            }

            private static int[] str_asc(string str)
            {
                if (str == null || str == string.Empty) return null;
                int[] result = new int[str.Length];
                for (int i = 0; i < str.Length; i++) result[i] = (int)str[i];
                return result;
            }

            private static long yiweitwo(long a, long b)
            {
                long z = 0x80000000;
                if ((z & a) != 0)
                {
                    a = (a >> 1);
                    a &= (~z);
                    a |= 0x40000000;
                    a = ((int)a >> (int)(b - 1));
                }
                else
                {
                    a = ((int)a >> (int)b);
                }
                return a;
            }

            private static int[] yiwei(long a, long b, long c)
            {
                a -= b; a -= c; a ^= (yiweitwo(c, 13));
                b -= c; b -= a; b ^= (a << 8);
                c -= a; c -= b; c ^= (yiweitwo(b, 13));
                a -= b; a -= c; a ^= (yiweitwo(c, 12));
                b -= c; b -= a; b ^= (a << 16);
                c -= a; c -= b; c ^= (yiweitwo(b, 5));
                a -= b; a -= c; a ^= (yiweitwo(c, 3));
                b -= c; b -= a; b ^= (a << 10);
                c -= a; c -= b; c ^= (yiweitwo(b, 15));
                return new int[] { (int)a, (int)b, (int)c };

            }

            private static int GoogleCH(int[] url)
            {
                int length = url.Length;
                long a = 0x9E3779B9;
                long b = 0x9E3779B9;
                long c = 0xE6359A60;
                int k = 0;
                int len = length;
                int[] mid;
                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));
                    mid = yiwei(a, b, c);
                    a = mid[0]; b = mid[1]; c = mid[2];
                    k += 12;
                    len -= 12;
                }
                c += length;
                switch (len)
                {
                    case 11:
                        {
                            c += (url[k + 10] << 24);
                            c += (url[k + 9] << 16);
                            c += (url[k + 8] << 8);
                            b += (url[k + 7] << 24);
                            b += (url[k + 6] << 16);
                            b += (url[k + 5] << 8);
                            b += (url[k + 4]);
                            a += (url[k + 3] << 24);
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;
                        }
                    case 10:
                        {
                            c += (url[k + 9] << 16);
                            c += (url[k + 8] << 8);
                            b += (url[k + 7] << 24);
                            b += (url[k + 6] << 16);
                            b += (url[k + 5] << 8);
                            b += (url[k + 4]);
                            a += (url[k + 3] << 24);
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;
                        }

                    case 9:
                        {
                            c += (url[k + 8] << 8);
                            b += (url[k + 7] << 24);
                            b += (url[k + 6] << 16);
                            b += (url[k + 5] << 8);
                            b += (url[k + 4]);
                            a += (url[k + 3] << 24);
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;

                        }

                    case 8:
                        {
                            b += (url[k + 7] << 24);
                            b += (url[k + 6] << 16);
                            b += (url[k + 5] << 8);
                            b += (url[k + 4]);
                            a += (url[k + 3] << 24);
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;

                        }

                    case 7:
                        {

                            b += (url[k + 6] << 16);
                            b += (url[k + 5] << 8);
                            b += (url[k + 4]);
                            a += (url[k + 3] << 24);
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;

                        }

                    case 6:
                        {
                            b += (url[k + 5] << 8);
                            b += (url[k + 4]);
                            a += (url[k + 3] << 24);
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;
                        }

                    case 5:
                        {
                            b += (url[k + 4]);
                            a += (url[k + 3] << 24);
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;

                        }

                    case 4:
                        {
                            a += (url[k + 3] << 24);
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;

                        }

                    case 3:
                        {
                            a += (url[k + 2] << 16);
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;
                        }
                    case 2:
                        {
                            a += (url[k + 1] << 8);
                            a += (url[k + 0]);
                            break;
                        }

                    case 1:
                        {
                            a += (url[k + 0]);
                            break;
                        }

                }
                mid = yiwei(a, b, c);
                return mid[2];
            }
        }
    }

  • 相关阅读:
    oracle 3大范式 理解
    RobHess的SIFT代码解析之RANSAC
    RobHess的SIFT代码解析步骤四
    RobHess的SIFT代码解析步骤三
    RobHess的SIFT代码解析步骤二
    《我的十年图像生涯》—王郑耀(西安交通大学)
    图像卷积
    多尺度分析方法及表达方式
    图像处理中双线性插值
    程序面试题——C实现
  • 原文地址:https://www.cnblogs.com/xchit/p/1828061.html
Copyright © 2011-2022 走看看