星空网 > 软件开发 > ASP.net

提取网站图片

protected void sub_Click(object sender, EventArgs e)
{
int i = 0;
string url = this.url.Text;
Directory.CreateDirectory("D:/aspnetjia/"+url);
string result = GetWebRequest(url);
//this.content.InnerText = result;
MatchCollection results = Regex.Matches(result, @"<img\s[^>]*src='/images/loading.gif' data-original=([""']*)(?<src>[^'""]*)\1[^>]*>", RegexOptions.IgnoreCase);
string[] d = new string[results.Count];
foreach (Match m in results)
{
d[i] = m.Groups["src"].Value;
i++;
}
for (int j = 0; j < d.Length; j++)
{
string jieguo = "";
int jj = j + 1;
string jie = d[j].ToString();
//if (jie.Contains(url))
//{
// jie.Replace(url,"");
//}
if (jie.Contains("www.") || jie.Contains("http"))
{
jieguo = "<a href='"+jie+"'><img src='/images/loading.gif' data-original='"+jie+"'></a>";
}
else
{
jieguo = "<a href='" + url + "/" + jie + "'><img src='/images/loading.gif' data-original='" + url + "/" + jie + "'></a>";
}
Random rand = new Random();//定义一个随机数,为了防止你要上传得图片重名
string[] strSpil = jie.Split('.');//将此地址用.号进行分割(img/1.jpg)
string strEnd = strSpil[strSpil.Length - 1].ToLower();//得到后面的("jpg", "gif", "bmp", "png","jpeg","JPG","GIF","BMP","PNG","JPEG")

string strName = DateTime.Now.ToString("yyyymmmddhhss") + rand.Next(100, 9999).ToString();//得到不同得名字
string strPointEnd = strName+"."+strEnd;

System.Net.WebClient myWebClient = new System.Net.WebClient();
if (jie.Contains("http"))
{
myWebClient.DownloadFile(jie, "D:/aspnetjia/" +url+"/"+strPointEnd);
}
else
{
myWebClient.DownloadFile(url +"/"+jie, "D:/aspnetjia/"+url +"/"+strPointEnd);
}
//Response.Write("正在下载第"+j+"张...");
}
Response.Write("请查看你D盘下aspnetjia文件夹");
}
private string GetWebRequest(string url)
{
Uri uri = new Uri(url);
WebRequest myReq = WebRequest.Create(uri);
WebResponse result = myReq.GetResponse();
Stream receviceStream = result.GetResponseStream();
StreamReader readerOfStream = new StreamReader(receviceStream, System.Text.Encoding.GetEncoding("utf-8"));
string strHTML = readerOfStream.ReadToEnd();
readerOfStream.Close();
receviceStream.Close();
result.Close();
return strHTML;
}

转载自:http://www.aspnetjia.com




原标题:提取网站图片

关键词:图片

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

孟加拉信用证:https://www.goluckyvip.com/tag/1590.html
amplecolor:https://www.goluckyvip.com/tag/15900.html
Amplifinity:https://www.goluckyvip.com/tag/15901.html
AMPM Podcast:https://www.goluckyvip.com/tag/15902.html
Amsmailer:https://www.goluckyvip.com/tag/15904.html
AMS广告:https://www.goluckyvip.com/tag/15905.html
独家丨B站广告位可跳转美团APP B站为电商平台引流再升级 :https://www.kjdsnews.com/a/1836410.html
百崖大峡谷生态旅游景区(探秘中国西南自然风光):https://www.vstour.cn/a/363176.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流