Extract site Pictures

Source: Internet
Author: User

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, @ "]*src= ([" "']* ') (? <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+ "' ></a>";
}
Else
{
Jieguo = "<a href=" + URL + "/" + Jie + "' ></a>";
}
Random rand = new Random ();//define a random number, in order to prevent you from uploading the picture duplicate name
string[] Strspil = Jie. Split ('. '); /This address is split with a. Number (img/1.jpg)
String strend = Strspil[strspil.length-1]. ToLower ();//Get Back ("jpg", "gif", "BMP", "PNG", "JPEG", "JPG", "gif", "BMP", "PNG", "JPEG")

String strName = DateTime.Now.ToString ("YYYYMMMDDHHSS") + Rand. Next (100, 9999). ToString ();//Get a different name
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 ("Downloading section" +j+ "...");
}
Response.Write ("Please check your D-disk under Aspnetjia folder");
}
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;
}

Reprinted from: http://www.aspnetjia.com

Extract site Pictures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.