代码改变世界

提取招聘职位信息

2012-08-15 18:04  C#与.NET探索者  阅读(187)  评论(0编辑  收藏  举报
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;

namespace 提取招聘职位信息
{
    class Program
    {
        static void Main(string[] args)
        {
            WebClient client = new WebClient();
            client.Encoding = Encoding.GetEncoding("GBK");
            string html = client.DownloadString("http://localhost:8080/【上海,IT-管理,计算机软件招聘,求职】-前程无忧.htm");

            //http://search.51job.com/job/46620099,c.html
            MatchCollection matches = Regex.Matches(html, "<[aA].*href=\"http://search.51job.com/job/\\d{8},c\\.html\".*>(.+)</[aA]>");
            int index = 0;
            for (int i = 0; i < matches.Count; i++)
            {
                if (matches[i].Success)
                {
                    index++;
                    Console.WriteLine(matches[i].Groups[1].Value);
                    //Console.WriteLine(matches[i].Value);
                }
            }
            Console.WriteLine("共{0}个职位信息。", index);
            Console.ReadKey();
        }
    }
}