zoukankan      html  css  js  c++  java
  • C# extract img url from web content then download the img

    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
                {
    
                }           
            }
  • 相关阅读:
    NYOJ题目22 素数求和
    最大连续子序列&&MAX SUM
    Computer Transformation
    #转 二分查找
    吃巧克力
    公司年会
    亲和串
    开门人和关门人
    找新朋友
    big number
  • 原文地址:https://www.cnblogs.com/Fred1987/p/12118123.html
Copyright © 2011-2022 走看看