下载图片到本地(未论证)
2015-12-19 21:47:20 访问(1389) 赞(0) 踩(0)
///
/// 下载图片到本地
/// ///
HTML
///
路径
///
年月
///
日
public string SaveUrlPics(string strHTML, string path)
{
string nowym = DateTime.Now.ToString("yyyy-MM"); //当前年月
string nowdd = DateTime.Now.ToString("dd"); //当天号数
path = path + nowym + "/" + nowdd;
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
string[] imgurlAry = GetImgTag(strHTML);
try
{
for (int i = 0; i < imgurlAry.Length; i++)
{
string preStr = System.DateTime.Now.ToString() + "_";
preStr = preStr.Replace("-", "");
preStr = preStr.Replace(":", "");
preStr = preStr.Replace(" ", "");
WebClient wc = new WebClient();
wc.DownloadFile(imgurlAry[i], path + "/" + preStr + imgurlAry[i].Substring(imgurlAry[i].LastIndexOf("/") + 1));
}
}
catch (Exception ex)
{
return ex.Message;
}
return strHTML;
}
标签:
下载图片到本地(未论证) 


上一条:
下一条:
相关评论
发表评论