首页 > 代码库 > 通过WebClient类来发起请求并下载html 抓取邮箱 图片
通过WebClient类来发起请求并下载html 抓取邮箱 图片
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_.]+@[-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="http://www.mamicode.com/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://www.mamicode.com/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 抓取邮箱 图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。