步步为营-19-正则表达式的简单应用

说明:现在我想查看博客园中,我都写了哪些随笔,都是什么时间写的.做一个数据的采集分析

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace 博客园统计
{
    class Program
    {
        static void Main(string[] args)
        {
            WebClient web = new WebClient();
            byte[] buffer = web.DownloadData(@"http://www.cnblogs.com/YK2012/");
            string html = Encoding.UTF8.GetString(buffer);
            MatchCollection mc = Regex.Matches(html, @"<a.+?homepage1.+?DayList.+?html.+?>(?<title>.+)</a>");
            MatchCollection name = Regex.Matches(html,@"@\s(?<time>.+)逍遥小天狼");
            Console.WriteLine("一共有{0}篇文章",mc.Count);
            for (int i = 0; i < mc.Count; i++)
            {
                if (mc.Count>0 && name.Count>0)
                {
                    Console.WriteLine(mc[i].Groups["title"]);
                    Console.WriteLine(name[i].Groups["time"]);
                }
            }
            Console.Read();
        }
    }
}
View Code

 

posted @ 2017-04-17 13:05  逍遥小天狼  阅读(208)  评论(0编辑  收藏  举报