BoKeYuanApp 一个拉取博客园信息的小软件

BoKeYuanApp是一个小程序。它能展示博客园历史统计信息,包括博客、随笔、文章 、 评论等;和个人统计信息,包括个人积分和排名。项目采用微软wpf框架,使用mvvm模式进行开发。图表展示使用LiveCharts。

已开源,代码在码云。

https://gitee.com/SmallUniv/BoKeYuanApp

重要接口介绍

  • 统计信息拉取接口

    https://www.cnblogs.com/aggsite/AggStats

  • 最新推荐博客和推荐博客排行接口

    https://www.cnblogs.com/aggsite/UserStats

  • 个人信息接口

    https://www.cnblogs.com/xinyf/mvc/blog/sidecolumn.aspx?blogApp=[个人博客id]

    比如,本人的id为xinyf,则,该接口为https://www.cnblogs.com/xinyf/mvc/blog/sidecolumn.aspx?blogApp=xinyf

开发思路:从接口中拉取信息,然后使用正则表达式解析。

代码示例:

public Tuple<int, int, int, int> ParseAggStats()
        {
            bool isfind = false;
            string returnstr = string.Empty;
            int index = 0;
            while (!isfind)
            {
                returnstr = HttpGetAggStats();
                index++;
                if (returnstr.Contains("<ul><li>博客"))
                {
                    isfind = true;
                }
                Console.WriteLine(index);
            }
            //<ul><li>博客 - <span>454322</span></li><li>随笔 - <span>6076429</span></li><li>文章 - <span>634171</span></li><li>评论 - <span>3150217</span></li></ul>

            {
                string p = @"<li>博客s*-s*<span>([d.]+)</span></li><li>随笔s*-s*<span>([d.]+)</span></li><li>文章s*-s*<span>([d.]+)</span></li><li>评论s*-s*<span>([d.]+)</span></li>";
                string ps = @"<li>博客s*-s*<span>d*</span></li>";
                Regex reg = new Regex(p);
                Match match = reg.Match(returnstr);
                string value0 = match.Groups[0].Value;
                string strBlog = match.Groups[1].Value;
                string strJotting = match.Groups[2].Value;
                string strArticle = match.Groups[3].Value;
                string strComment = match.Groups[4].Value;
                string strvalue5 = match.Groups[5].Value;
                Console.WriteLine(match);

                int blog = int.Parse(match.Groups[1].Value);
                int jotting = int.Parse(match.Groups[2].Value);
                int article = int.Parse(match.Groups[3].Value);
                int comment = int.Parse(match.Groups[4].Value);

                return new Tuple<int, int, int, int>(blog, jotting, article, comment);

            }

            {
                string p = @"<li>随笔s*-s*<span>([d.]+)</span></li>";
                string ps = @"<li>随笔s*-s*<span>d*</span></li>";
                Regex reg = new Regex(p);

                Match match = reg.Match(returnstr);
                string value0 = match.Groups[0].Value;
                string value = match.Groups[1].Value;
                string value2 = match.Groups[2].Value;
                Console.WriteLine(match);
            }
        }

上面函数解析返回园子统计信息。

效果示例:

园子统计信息展示

个人统计信息展示

原文地址:https://www.cnblogs.com/xinyf/p/10132601.html