C # Implementation Crawl HD beauty sister paper pictures

Source: Internet
Author: User

C # Implementation Crawl HD beauty sister paper pictures


The code is as follows:


private void Dofetch (int pagenum)

{

ThreadPool.QueueUserWorkItem (_ =

{

HttpWebRequest request = (HttpWebRequest) webrequest.create ("

Beauty photography? page= "+ pagenum);

Request. Credentials = System.Net.CredentialCache.DefaultCredentials;

HttpWebResponse response = (HttpWebResponse) request. GetResponse ();

if (response. StatusCode = = Httpstatuscode.ok)

{

using (StreamReader sr = new StreamReader (response. GetResponseStream ()))

{

List<uri> links = Fetchlinksfromsource (Sr. ReadToEnd ());

Console.WriteLine ("=========================" + pagenum + "Fatch end==========================");

}

}

});

}

Private list<uri> Fetchlinksfromsource (string htmlsource)

{

List<uri> links = new list<uri> ();

String regeximgsrc = @ "]*?src\s*=\s*[" "'"? ([^ ' "" ">]+?) [ ‘””] [^>]*?> ";

MatchCollection matchesimgsrc = regex.matches (Htmlsource, regeximgsrc, Regexoptions.ignorecase | Regexoptions.singleline);

foreach (Match m in matchesimgsrc)

{

String href = m.groups[1]. Value;

if (checkisurlformat (HREF))

{

Links. ADD (new Uri (href));

Console.WriteLine (HREF);

}

Else

Continue

using (WebClient mywebclient = new WebClient ())

{

Try

{

Mywebclient.downloadfile (new Uri (HREF), System.IO.Path.Combine (Globepath, System.IO.Path.GetRandomFileName () + System.IO.Path.GetExtension (HREF)));

}

catch (Exception ex)

{

Console.WriteLine (ex. Message);

}

}

}

return links;

}

The above is the whole content of this article, we can freely expand Oh, you know, I hope you can like.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # Implementation Crawl HD beauty sister paper pictures

This address: http://www.paobuke.com/develop/c-develop/pbk23114.html






Related content. NET C # using zxing to generate, identify QR codes/Barcodes C # Implement polling algorithm instance code c#3.0 use EventLog class to write Windows event log methods C # virtual function Usage Instance analysis
How do you describe C # in 4 deep-copy methods in C #? D??? 3?? èí?tê?? Ò?°2x°êμ?? ′ú???? Íc# How to operate the IIS root lock system in C # multithreaded programming (III)

C # Implementation Crawl HD beauty sister paper 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.