http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3086|回复: 3

[例子源码] c# 获取google pr值

[复制链接]
发表于 2014-9-5 09:59:51 | 显示全部楼层 |阅读模式
  


QQ图片20140905095546.png
我是用www.baidu.com 这域名测试的
根据不同域名的计算 得出 ch 的值
然后post  如果这个地址。 直接敲这个pr 接口 地址
http://www.google.cn/search?client=navclient-auto&features=Rank:&q=info:http://www.baidu.com&ch=62009202064


返回错误页面。请管理员赐教  谢谢。
  string responseFromServer = "";
                string s = CalculateChecksum(strUrl);

                //try
                //{
                //    HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(@"http://www.google.cn/search?client=navclient-auto&features=Rank:&q=info:" + strUrl + "&ch=" + s);

                // //   HttpWReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)";
                // //   HttpWReq.Accept = @"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, */*";


                //    HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
                //    Stream dataStream = HttpWResp.GetResponseStream();
                //    StreamReader reader = new StreamReader(dataStream, System.Text.Encoding.GetEncoding("GB2312"));
                //    responseFromServer = reader.ReadToEnd();
                //}
                //catch(Exception ex)
                //{

                //}
                //string[] sp = responseFromServer.Split(':');
                //if (sp.Length == 3)
                //{
                //    strResult = "谷歌PR:" + sp[2].ToString();
                //}
                //else
                //{
                //    strResult = "谷歌PR:0";
                //}

                string url="http://www.google.cn/search?client=navclient-auto&features=Rank:&q=info:" + strUrl + "&ch=" + s+"";
                responseFromServer = GetUrltoHtml(url, 2000);

                string[] sp = responseFromServer.Split(':');
                if (sp.Length == 3)
                {
                    strResult = "谷歌PR:" + sp[2].ToString();
                }
                else
                {
                    strResult = "谷歌PR:0";
                }




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2014-9-5 10:19:21 | 显示全部楼层
问题已经解决  。贴一下我的解决方案已经源码



public  class CheckSum
    {

        ///
        /// Google PageRank的Checksum算法。
        ///

        public static int GooglePR(string url)
        {
            string checksum = GoogleCH(url);
            string query = string.Format("http://toolbarqueries.google.com/tbr?client=navclient-auto&ch={0}&features=Rank&q=info:{1}", checksum, url);

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(query);
                string response = new StreamReader(request.GetResponse().GetResponseStream()).ReadToEnd();
                if (response.Length == 0)
                    return 0;
                else
                    return int.Parse(Regex.Match(response, "Rank_1:[0-9][0-9]+)").Groups[1].Value);
            }
            catch (Exception)
            {
                return -1;
            }
        }

        private const UInt32 GOOGLE_MAGIC = 0xE6359A60;
        private static void _mix(ref UInt32 a, ref UInt32 b, ref UInt32 c)
        {
            a -= b; a -= c; a ^= c >> 13;
            b -= c; b -= a; b ^= a << 8; c -= a; c -= b; c ^= b >> 13;
            a -= b; a -= c; a ^= c >> 12;
            b -= c; b -= a; b ^= a << 16; c -= a; c -= b; c ^= b >> 5;
            a -= b; a -= c; a ^= c >> 3;
            b -= c; b -= a; b ^= a << 10; c -= a; c -= b; c ^= b >> 15;
        }
        public static string GoogleCH(string url)
        {
            url = string.Format("info:{0}", url);

            int length = url.Length;

            UInt32 a, b;
            UInt32 c = GOOGLE_MAGIC;

            int k = 0;
            int len = length;

            a = b = 0x9E3779B9;

            while (len >= 12)
            {
                a += (UInt32)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k + 3] << 24));
                b += (UInt32)(url[k + 4] + (url[k + 5] << 8) + (url[k + 6] << 16) + (url[k + 7] << 24));
                c += (UInt32)(url[k + 8] + (url[k + 9] << 8) + (url[k + 10] << 16) + (url[k + 11] << 24));
                _mix(ref a, ref b, ref c);
                k += 12;
                len -= 12;
            }
            c += (UInt32)length;
            switch (len) /* all the case statements fall through */
            {
                case 11:
                    c += (UInt32)(url[k + 10] << 24);
                    goto case 10;
                case 10:
                    c += (UInt32)(url[k + 9] << 16);
                    goto case 9;
                case 9:
                    c += (UInt32)(url[k + 8] << 8);
                    goto case 8;
                /* the first byte of c is reserved for the length */
                case 8:
                    b += (UInt32)(url[k + 7] << 24);
                    goto case 7;
                case 7:
                    b += (UInt32)(url[k + 6] << 16);
                    goto case 6;
                case 6:
                    b += (UInt32)(url[k + 5] << 8);
                    goto case 5;
                case 5:
                    b += (UInt32)(url[k + 4]);
                    goto case 4;
                case 4:
                    a += (UInt32)(url[k + 3] << 24);
                    goto case 3;
                case 3:
                    a += (UInt32)(url[k + 2] << 16);
                    goto case 2;
                case 2:
                    a += (UInt32)(url[k + 1] << 8);
                    goto case 1;
                case 1:
                    a += (UInt32)(url[k + 0]);
                    break;
                default:
                    break;
                /* case 0: nothing left to add */
            }

            _mix(ref a, ref b, ref c);

            return string.Format("6{0}", c);
        }

    }
 楼主| 发表于 2014-9-5 10:19:54 | 显示全部楼层
调用一下这个类就可以登录饿 。
发表于 2014-9-5 11:44:15 | 显示全部楼层
我只是路过打酱油的。
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-29 09:03

© 2014-2021

快速回复 返回顶部 返回列表