基本信息
源码名称:C# 网络爬虫自动下载图片(入门级示例)
源码大小:0.03M
文件格式:.rar
开发语言:C#
更新时间:2016-02-15
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net; using System.IO; using System.Text.RegularExpressions; using System.Collections; namespace 试一下网络没有http { class Program { static ArrayList array = new ArrayList(); static int k=1; static string[] str = new string[10000]; static void Main(string[] args) { visit("http://www.autohome.com.cn/beijing/"); } public static void visit(string xx) { WebRequest wq = WebRequest.Create(xx); WebResponse wqs = wq.GetResponse(); Stream s = wqs.GetResponseStream(); StreamReader sr = new StreamReader(s, Encoding.Default); string x = sr.ReadToEnd().ToString(); // Console.WriteLine(x); string partten = @"(https://|http://)?([\w-] \.) [\w-] (/[\w- ./?%&=]*)?"; string partten2 = @"(http://|http://)[.0-9a-zA-Z\u2E80-\u9FFF]*/[.0-9a-zA-Z\u2E80-\u9FFF]*/"; string partten3 = @"(http:).*"; string partten4 = @"src=""[\.//:0-9a-zA-Z\u2E80-\u9FFF]*"""; string partten5 = @"(http://|http://)[\.//:0-9a-zA-Z\u2E80-\u9FFF]*"; Regex regex = new Regex(partten4, RegexOptions.IgnoreCase); Regex regex2 = new Regex(partten5, RegexOptions.IgnoreCase); MatchCollection m = regex.Matches(x); // m.NextMatch(); StreamWriter sw = new StreamWriter(@"C:\Users\sss\Desktop\网络爬虫.txt"); Console.WriteLine(m.Count ); foreach (Match ma in m) { // Console.WriteLine(ma.ToString()); Match m2 = regex2.Match(ma.ToString()); sw.WriteLine(m2.ToString ()); str[k] = m2.ToString(); WebClient myclient = new WebClient(); myclient.DownloadFile(m2.ToString(), @"C:\Users\sss\Desktop\pic\" k @".jpg"); k ; } sw.Close(); /* HttpWebRequest request = (HttpWebRequest)WebRequest.Create(""); WebResponse response = request.GetResponse(); Stream inStream = response.GetResponseStream(); l = inStream.Read(buffer, 0, buffer.Length); */ // if (k <= array.Count) // visit(xx); // else return; }//visit() /* public void travel(string[] str) { for (int i = 0; i < str.Length; i ) { } }*/ }//class }