通過WebClient類來發起請求並下載html 抓取郵箱 圖片

來源:互聯網
上載者:User

標籤: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 抓取郵箱 圖片

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.