当前位置: 移动技术网 > IT编程>开发语言>c# > C# extract img url from web content then download the img

C# extract img url from web content then download the img

2019年12月30日  | 移动技术网IT编程  | 我要评论
static void main(string[] args)
        {
            webclientdemo();
            
            console.readline();
        }

         
        static void webclientdemo()
        {
            webcontent = file.readalltext("img2.txt");
            var urlslist = webcontent.split(new string[] { "\"", "" }, stringsplitoptions.none).tolist().where(x => x.startswith("http")).where(x => x.endswith("jpg") || x.endswith(".png") || x.endswith(".jpeg"));

            foreach (var ul in urlslist)
            {
                webclientdownload(ul);
            }
        }

        static void webclientdownload(string url)
        {
            try
            {
                using (webclient wc = new webclient())
                {               
                   
                    string[] urls = url.split(new string[] { "/" }, stringsplitoptions.none);
                    string filename = "imgs2\\"+ urls[urls.length - 1];
                    wc.downloadfile(url, filename);
                    ++num;
                    console.writeline(url);
                }
            }
            catch
            {

            }           
        }

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网