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

Tricia ·
更新时间:2024-11-11
· 691 次阅读

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

代码如下:
private void DoFetch(int pageNum)
        {
            ThreadPool.QueueUserWorkItem(_ =>
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://me2-sex.lofter.com/tag/美女摄影?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 = @"<img[^>]*?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;
        }

您可能感兴趣的文章:C#基于正则表达式实现获取网页中所有信息的网页抓取类实例C#使用正则表达式抓取网站信息示例C#正则函数用法实例【匹配、替换、提取】C#中正则表达式的3种匹配模式C#正则匹配RegexOptions选项的组合使用方法C#匹配中文字符串的4种正则表达式分享c#使用正则表达式匹配字符串验证URL示例c#匹配整数和小数的正则表达式C# 抓取网页内容的方法C#实现抓取和分析网页类实例C#基于正则表达式抓取a标签链接和innerhtml的方法



美女 C# 图片

需要 登录 后方可回复, 如果你还没有账号请 注册新账号