C#实现简单的网页爬虫
2015-05-23 14:02
309 查看
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace _2015._5._23通过WebClient类发起请求并下载html { class Program { static void Main(string[] args) { #region 抓取网页邮箱 //string url = "http://zhidao.baidu.com/link?url=cvF0de2o9gkmk3zW2jY23TLEUs6wX-79E1DQVZG7qaBhEVT_xlh6TO7p0W4qwuAZ_InLymC_-mJBBcpdbzTeq_"; //WebClient wc = new WebClient(); //wc.Encoding = Encoding.UTF8; //string str = wc.DownloadString(url); //MatchCollection matchs= Regex.Matches(str,@"\w+@([-\w])+([\.\w])+",RegexOptions.ECMAScript); //foreach (Match item in matchs) //{ // Console.WriteLine(item.Value); //} //Console.WriteLine(matchs.Count); #endregion #region 抓取网页图片 //WebClient wc = new WebClient(); //wc.Encoding = Encoding.UTF8; ////下载源网页代码 //string html = wc.DownloadString("http://dongxi.douban.com/?dcs=top-nav&dcm=douban"); //MatchCollection matches= Regex.Matches(html,"<img.*src=\"(.+?)\".*>"); //foreach (Match item in matches) //{ // //下载图片到指定路径 // wc.DownloadFile(item.Groups[1].Value,@"c:\mv\"+Path.GetFileName(item.Groups[1].Value)); //} //Console.WriteLine(matches.Count); #endregion 爬一些信息 WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; string html = wc.DownloadString("http://www.lagou.com/"); MatchCollection matches= Regex.Matches(html,"<a.*jobs.*>(.*)</a>"); foreach (Match item in matches) { Console.WriteLine(item.Groups[1].Value); } Console.WriteLine(matches.Count); Console.ReadKey(); } } }
相关文章推荐
- c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)
- c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)
- c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)
- c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)
- 基于C#实现网页爬虫
- java实现的简单网页爬虫:Servlet + MySQL5.5(二)
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- C#实现网页爬虫
- 简单网络爬虫应用,解析网页,实现定时通知、提示
- java实现的简单网页爬虫:Servlet 搜索引擎核心爬虫程序(三)
- 使用C# 实现简单的爬虫
- python实现的一个简单的网页爬虫
- C# 网络编程之网页简单下载实现
- 巧用C#webbrowser以及Application.DoEvents()实现采集动态网页的爬虫机器人
- 网页爬虫抓取URL简单实现
- 巧用C#webbrowser以及Application.DoEvents()实现采集动态网页的爬虫机器人
- c#简单实现提取网页内容
- Python入门简单的静态网页爬虫2.0 (实现各模块的具体方法)
- 简单网络爬虫实现<爬取网页邮箱>
- 简单的java爬虫抓取网页实现代码(未测试)