C# 抓去网站图片
![](https://pic002.cnblogs.com/images/2011/301072/2011053116292855.png)
没有加入线程
/// <summary>
/// 提取图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOK_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
string str = client.DownloadString(txtHTML.Text.Trim());
MatchCollection mc = Regex.Matches(str, "<img.+?src=(['\"]?)([^>\\s]+)\\1.*?>");
int index = 0;
foreach (Match item in mc)
{
string imgpath = item.Groups[2].Value;
lbImage.Text = imgpath;
if (imgpath.IndexOf("http:") > -1)
{
client.DownloadFile(imgpath, @"D:\Imges\" + DateTime.Now.Millisecond + index + ".jpg");
}
else
{
imgpath = txtHTML.Text.Trim() + imgpath;
client.DownloadFile(imgpath, @"D:\Imges\" + DateTime.Now.Millisecond + index + ".jpg");
}
index++;
}
MessageBox.Show("OK!");
}