c#实现抓取高清美女妹纸图片
c#实现抓取高清美女妹纸图片
发布时间:2016-12-28 来源:查字典编辑
摘要:c#实现抓取高清美女妹纸图片复制代码代码如下:privatevoidDoFetch(intpageNum){ThreadPool.Queue...

c#实现抓取高清美女妹纸图片

复制代码 代码如下:

private void DoFetch(int pageNum)

{

ThreadPool.QueueUserWorkItem(_ =>

{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://me2-sex.lofter.com/tag/美女摄影" + 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 = @"<img[^>]*"']" >]+"][^>]*";

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;

}

以上就是本文的全部内容了,大家可以自由扩展哦,你懂得,希望大家能够喜欢。

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C#教程学习
热门C#教程学习
编程开发子分类