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];
            }
        }
    }

  • 相关阅读:
    作品-系统-[原生开发]新蓝景CRM管理系统
    作品-网站-[二次开发]汇名惠商城
    js声明json数据,打印json数据,遍历json数据,转换json数据为数组
    js 鼠标滚动到某屏时,加载那一屏的数据,仿京东首页楼层异步加载模式
    js转换数据类型为浮点型,并取两位小数点
    php判断是否是微信客户端的浏览器访问
    百度地图API地理位置和坐标转换
    php 对象中连贯执行方法
    php extract 函数的妙用 数组键名为声明为变量,键值赋值为变量内容
    php 获取远程图片保存到本地
  • 原文地址:https://www.cnblogs.com/xchit/p/1828061.html
Copyright © 2011-2022 走看看