zoukankan      html  css  js  c++  java
  • 步步为营-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

  • 相关阅读:
    学习进度第三周
    四则运算3
    学习进度第二周
    单元测试
    四则运算2
    学习进度第一周
    四则运算1
    构建之法阅读笔记01
    linux: 讨论一下网络字节序--------大端与小端的差别
    linux编程:线程条件同步
  • 原文地址:https://www.cnblogs.com/YK2012/p/6722402.html
Copyright © 2011-2022 走看看