zoukankan      html  css  js  c++  java
  • .net下载图片,去下载重复的图片,保存数据库,保存图片

        public static string DowImg(string content1, string key)
        {
            string content = content1;
            MatchCollection m = getregduo("<img.+?>", content);
            foreach (Match item in m)
            {//

                string imgurl = getreg("src=\"(.+?)\"", item.Value);//原图片url地址
                if (imgurl.IndexOf("lkjfds")!=-1)
                {
                    string ddd = "ddd";
                }
      string houzui = imgurl.Substring(imgurl.LastIndexOf("."));//图片的后缀
              
                string imgname = Guid.NewGuid().ToString() + houzui;
                string name = "http://www.lkjfds.com/taoimg/" + key + "/" + imgname;//改后的图片路径;
              
              
           
                try
                {  
                    DAL.Database.ExecProc("insert into img(url,houurl) values('" + imgurl + "','"+name+"')");//把已有的链接放入数据库
                    content = content.Replace(imgurl, name);
                }
                catch (Exception e)
                {
                    if (e.ToString().IndexOf("索引") != -1)//说明这幅图片已经存在于数据库了
                    {
                        name = DAL.Database.ReturnScalar("select houurl from img where url='" + imgurl + "'").ToString();
                        content = content.Replace(imgurl, name);
                        continue;
                    }
                    throw;
                }
               // 如果不是就下载图片
                Stream ss = httpweb.getGet(imgurl, new System.Net.CookieContainer());//下载图片
                Image img = Image.FromStream(ss);
                img.Save(Environment.CurrentDirectory + "/" + key + "/" + imgname);//保存图片
            }
            return content;
        }

  • 相关阅读:
    JavaScript操作DOM对象
    QTP(13)
    QTP(12)
    QTP(11)
    QTP(10)
    QTP(9)
    QTP(8)
    QTP(7)
    QTP(6)
    QTP(5)
  • 原文地址:https://www.cnblogs.com/djhama/p/1796221.html
Copyright © 2011-2022 走看看