欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-13 10:49:34
c#实现抓取高清美女妹纸图片 复制代码 代码如下: private void dofetch(int pagenum)     ...

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

复制代码 代码如下:

private void dofetch(int pagenum)
        {
            threadpool.queueuserworkitem(_ =>
            {
                httpwebrequest request = (httpwebrequest)webrequest.create("美女摄影?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;
        }

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

上一篇:

下一篇: