| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> .Net源码 >> 实用功能 >> .Net源码正文
最新推荐 更多内容
C#查询谷歌pr数值(Miroslav Stampar提供)           ★★★
C#查询谷歌pr数值(Miroslav Stampar提供)
作者:Miroslav…     来源:Miroslav Stampar     更新时间:2011-3-16 16:23:01
之前乐博网有发过asp.net版的  这次是来自Miroslav Stampar提供的 C#查询谷歌pr数值 源代码
C#源代码如下:
//by Miroslav Stampar (miroslav.stampar(at)gmail.com)
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

namespace GooglePR
{
    class Program
    {
        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);
        }
        public static int GooglePR(string url)
        {
            string checksum = GoogleCH(url);
            string query = string.Format("http://www.google.com/search?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;
            }
        }

        static void Main(string[] args)
        {
            // [url]http://www.example.com/[/url] - Checksum: 6540747202 
            Console.Write("Enter URL: ");
            string url = Console.ReadLine();
            Console.WriteLine("Google checksum: {0}", GoogleCH(url));
            Console.WriteLine("Google pagerank: {0}", GooglePR(url));
        }
    }
}
  • 上一篇:

  • 下一篇: 没有了
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    查询google的pr数值的Asp.net源码

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]