首頁 / CompScience / Programming / Languages / C# / PageRank挖挖挖

PageRank挖挖挖

既然Google Blogger版的誰來我家寫的差不多了,雖然還有一個小小問題,說小也不小,因為會讓程式變成不自動,不過短期ㄚ琪還沒有解,今天靈機一動又想說,乾脆順便查一下這些追蹤者的PageRank好了,馬上捲起袖子動手做吧,這一次更快了,參考網上的C#程式,馬上就手到擒來,張貼一下程式碼,大家參考一下吧:

public static class GooglePageRank
    {
        private static void Mix(ref uint a, ref uint b, ref uint 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;
        }

        private static string GoogleChecksum(string url)
        {
            uint GoogleMagic = 0xE6359A60;

            uint a, b;
            uint c = GoogleMagic;

            a = b = 0x9E3779B9;

            int k = 0;
            int length = url.Length;

            //Algorithm
            while (length >= 12)
            {
                a += (uint)(url[k + 0] + (url[k + 1] << 8) + (url[k + 2] << 16) + (url[k + 3] << 24));
                b += (uint)(url[k + 4] + (url[k + 5] << 8) + (url[k + 6] << 16) + (url[k + 7] << 24));
                c += (uint)(url[k + 8] + (url[k + 9] << 8) + (url[k + 10] << 16) + (url[k + 11] << 24));

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

                k += 12;
                length -= 12;
            }

            c += (uint)url.Length;

            //All cases fall through
            switch (length)
            {
                case 11:
                    c += (uint)(url[k + 10] << 24);
                    goto case 10; //fall through
                case 10:
                    c += (uint)(url[k + 9] << 16);
                    goto case 9;
                case 9:
                    c += (uint)(url[k + 8] << 8);
                    goto case 8;
                case 8:
                    b += (uint)(url[k + 7] << 24);
                    goto case 7;
                case 7:
                    b += (uint)(url[k + 6] << 16);
                    goto case 6;
                case 6:
                    b += (uint)(url[k + 5] << 8);
                    goto case 5;
                case 5:
                    b += (uint)(url[k + 4]);
                    goto case 4;
                case 4:
                    a += (uint)(url[k + 3] << 24);
                    goto case 3;
                case 3:
                    a += (uint)(url[k + 2] << 16);
                    goto case 2;
                case 2:
                    a += (uint)(url[k + 1] << 8);
                    goto case 1;
                case 1:
                    a += (uint)(url[k + 0]);
                    break;
                default:
                    break;
            }

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

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

        public static int GetPageRank(string url)
        {
            //Calculate URL checksum
            string checkSum = GoogleChecksum(“info:” + url);
            string file = “http://toolbarqueries.google.com/search?client=navclient-auto&ch=” + checkSum + “&features=Rank&q=info:” + url;

            try
            {
                //Request PR from Google
                WebRequest request = WebRequest.Create(file);
                WebResponse response = request.GetResponse();

                StreamReader reader = new StreamReader(response.GetResponseStream());
                string data = reader.ReadToEnd();

                reader.Close();
                response.Close();

                //Parse PR from string
                int = -1;
                if (data.IndexOf(‘:’) != -1)
                {
                    data = data.Substring(data.LastIndexOf(‘:’) + 1);
                }

                int.TryParse(data, out pageRank);

                return pageRank;
            }
            catch (Exception)
            {
                return -1;
            }
        }
    }

又挖到黃金了~~~

呼!為了找出

holder.currentBlogUrl = "http://xxxxx.yyyyy.zzzz/";
這樣的字串,搞了w+跟s+都不是,弄了一陣子,注意看手冊才發現原來.+才是我要的,呼,真累~
馬上成為工作達人的Fans

About ㄚ琪

工作達人Fun Taiwan的創辦者及總編,可以在這裡更認識他。

發表迴響

你的電子郵件位址並不會被公開。 Required fields are marked *

*

Scroll To Top

 好吃、好玩、旅遊、試吃、試用、邀稿、SEO

歡迎洽詢:flylinux@gmail.com

➨ 國外美食旅遊  日本東京自由行  美國猶他加州自由行  韓國釜山首爾慶州自由行 │ 泰國馬來西亞新加坡自由行  澳門廣東香港自由行日本九州奈良京阪自由行 │澳洲墨爾本坎培拉雪梨自由行 │中國北京自由行 

紅屋頂加級大阪難波飯店 (Red Roof Plus Osaka Namba) 日本大阪紅屋頂加級大阪難波飯店 (Red Roof Plus Osaka Namba)激推