using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Net;
namespace 下载网页图片
{
class Program
{
static void Main(string[] args)
{
string path = @"C:/Users/hutao/Desktop/桌面文档 20120921/正则表达式/美女图片/default.htm";
string str = File.ReadAllText(path);
List list = new List();
MatchCollection ms = Regex.Matches(str, "src=\"(.+)\" />");
if (ms.Count != 0)
{
for (int i = 0; i < ms.Count; i++)
{
if (ms[i].Success)
{
list.Add(ms[i].Groups[1].Value);
}
}
}
WebClient c = new WebClient();
string ss;
string name;
for (int i = 0; i < list.Count; i++)
{
ss = Path.GetDirectoryName(path) + "\\" + list[i];
c.DownloadFile(ss, string.Format("{0}.jpg",i));
}
Console.WriteLine("OK");
Console.ReadKey();
}
}
}