简单的C#爬虫
2017-10-26 14:34
218 查看
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# Actor的消息执行方式(5):一个简单的网络爬虫
- c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)
- 使用C# 实现简单的爬虫
- 使用C# 实现简单的爬虫
- C#实现简单的网页爬虫
- 学习:C#实现一个简单的爬虫
- c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)
- 开源一个C#写的小爬虫,简单实用
- C#简单爬虫核心代码
- 适合C# Actor的消息执行方式(5):一个简单的网络爬虫
- C#简单爬虫案例分享
- c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)
- 爬虫技术(四)-- 简单爬虫抓取示例(附c#代码)
- 爬虫技术 -- 进阶学习(七)简单爬虫抓取示例(附c#代码)
- C#简单使用:ListView中使用ContextMenu
- extern外部方法使用C#简单例子
- xmlHTTP xmlDOC 与 C#中DataSet的结合 实现AJAX简单示例
- 网络编程C#篇(二):Socket无连接简单实例 推荐