標籤:end 代碼 reg stat arc hot html style acs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.Text.RegularExpressions;using System.IO;namespace 通過WebClient類來發起請求並下載html 抓取郵箱 圖片{ class Program { static void Main(string[] args) { #region 抓取網頁email //string url = "http://192.168.1.100:8080/提取Email.htm"; ////1.根據網址下載對應html字串 //WebClient wc = new WebClient(); //wc.Encoding = Encoding.UTF8; //string html = wc.DownloadString("http://192.168.1.100:8080/提取Email.htm"); ////2.從下載到字串中提取Email,並把提取到的Email寫入到文字檔中 //MatchCollection matches = Regex.Matches(html, @"[-a-zA-Z0-9_.][email protected][-a-zA-Z0-9]+(\.[a-zA-Z0-9]+){1,}"); //using (StreamWriter writer = new StreamWriter("email.txt")) //{ // //遍曆提取到的email // foreach (Match item in matches) // { // //Console.WriteLine(item.Value); // writer.WriteLine(item.Value); // } //} //Console.ReadKey(); #endregion #region 抓取網頁圖片 //WebClient wc = new WebClient(); ////1.下載網頁原始碼 //string html = wc.DownloadString("http://192.168.1.100:8080/美女圖片/美女們.htm"); ////2.提取網頁中的圖片,其實就是<img>標籤 ////<img src="hotgirls/00_00.jpg" /> //MatchCollection matches = Regex.Matches(html, @"<img\s+"" src=""(.+)""\s*/>"); //foreach (Match item in matches) //{ // string imgPath = "http://192.168.1.100:8080/美女圖片/" + item.Groups[1].Value; // //下載圖片 // wc.DownloadFile(imgPath, @"c:\mv\" + Path.GetFileName(imgPath)); //} //Console.WriteLine("ok"); //Console.ReadKey(); #endregion #region 抓取職位資訊 WebClient webClient = new WebClient(); string html = webClient.DownloadString("http://192.168.1.100:8080/【上海,IT-管理,電腦軟體招聘,求職】-前程無憂.htm"); //<a href="http://search.51job.com/job/46621778,c.html" onclick="zzSearch.acStatRecJob( 1 );" class="jobname" target="_blank">ERP專案經理</a> MatchCollection matches = Regex.Matches(html, @"<a\s+href=""http://search.51job.com/job/[0-9]{8},c.html"".+>(.+)</a>"); foreach (Match item in matches) { Console.WriteLine(item.Groups[1].Value); } Console.WriteLine("共{0}個職位資訊。", matches.Count); Console.ReadKey(); #endregion } }}
通過WebClient類來發起請求並下載html 抓取郵箱 圖片