我想做到,复制网上的文章。就直接把图片抓取保存到本地来。。不知道在asp.net怎么实现?对了。有没有这个功能的编辑器推介一下。。谢谢 

解决方案 »

  1.   

    首先用正则从文章中匹配出所有图片地址;
    然后用WebClient类下载到本地就可以了(下载图片这一步在文章入库的时候实现就可以了)using System.Net;
    //下载网络文件
    //fileurl文件或图片地址
    public bool DownloadPIC(string fileurl)
    {
    WebClient myWebClient = new WebClient();
    NewFileName=System.DateTime.Now.ToFileTime()+".GIF";
    try
    {
      myWebClient.DownloadFile(fileurl,Server.MapPath("~\\Picture\\"+NewFileName));
      return true;
    }
    catch
    {
      return false;
    }
    }
      

  2.   


    fck可以么??我用的就是,好像没这个功能吧??
      

  3.   

    首先需要获取网页的html源代码,把内容保存起来,然后分析文章内容,把有关图片转换成绝对URL地址,然后利用网络流的方式下载这些图片,保存到本地机器。
      

  4.   

        public string getWebClientImg(string url, string sPath)
        {
            if (isUrl(url))
            {
                string FileName = url.Substring(url.LastIndexOf("/") + 1);
                string extName = FileName.Substring(FileName.LastIndexOf(".") + 1);
                if (extName == "jpg" || extName == "gif")
                {
                    try
                    {
                        string rdn = Random();
                        string StringFileName = "";
                        DateTime dt = System.DateTime.Now;
                        StringFileName = (dt.ToString()).Replace(":", "");
                        StringFileName = StringFileName.Replace("-", "");
                        StringFileName = StringFileName.Replace(" ", "");
                        StringFileName = StringFileName + rdn + "." + extName;
                        WebClient wc = new WebClient();
                        wc.DownloadFile(url, @sPath + "\\pictem\\" + StringFileName);
                        return StringFileName;
                    }
                    catch (WebException we)
                    {
                        //HttpContext.Current.Response.Write(we.Message);
                        //HttpContext.Current.Response.End();
                        return "nopicture.jpg";
                    }
                }
                else
                {
                    try
                    {
                        string rdn = Random();
                        string StringFileName = "";
                        DateTime dt = System.DateTime.Now;
                        StringFileName = (dt.ToString()).Replace(":", "");
                        StringFileName = StringFileName.Replace("-", "");
                        StringFileName = StringFileName.Replace(" ", "");
                        StringFileName = StringFileName + rdn + ".jpg";
                        WebClient wc = new WebClient();
                        wc.DownloadFile(url, @sPath + "\\pictem\\" + StringFileName);
                        return StringFileName;
                    }
                    catch (WebException we)
                    {
                        //HttpContext.Current.Response.Write(we.Message);
                        //HttpContext.Current.Response.End();
                        return "nopicture.jpg";
                    }
                }
            }
            else
            {
                if (url.IndexOf("uploadpic") >= 0)
                {
                    return url;
                }
                else
                {
                    return "nopicture.jpg";
                }
            }
        }
      

  5.   

    如何用正则表达式从HTML分析出我想要的图片呢?
      

  6.   

    解析html代码中的图片的正则csdn上面很多,具本要看你从代码中加入图的格式,我随手写了个,没测试:int iCount=0;
    string strhtml='你html框里面的代码';
    ArrayList s=praseimg(strhtml);
    if (s.Count>0)
    {
      for (int i=0;i<s.Count;i++)
      {
        string picurl=DownloadPIC(Convert.ToString(s[i]));
        if (picurl!="") 
        {
          strhtml=strhtml.Replace(Convert.ToString(s[i]),picurl) //替换图片的路径为本地路径;
          iCount++;
        }
      } 
    }//正则表达式从HTML分析出所有图片
    function ArrayList praseimg(string str)
    {
    ArrayList s=new ArrayList();
    System.Text.RegularExpressions.Regex  reg=new  System.Text.RegularExpressions.Regex("<img[^>]*?src=['\"]?(<src>.*[^'\"])['\"]?.*?>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);  
    System.Text.RegularExpressions.MatchCollection m = reg.Matches(str); 
    for (int i = 0; i < m.Count; i++) s.Add(m[i].Groups["value"].ToString());
    }//下载网络文件
    //fileurl文件或图片地址
    public string DownloadPIC(string fileurl)
    {
    WebClient myWebClient = new WebClient();
    NewFileName=System.DateTime.Now.ToFileTime()+".GIF";
    try
    {
      myWebClient.DownloadFile(fileurl,Server.MapPath("~\\Picture\\"+NewFileName));
      return "Picture\\"+NewFileName;
    }
    catch
    {
      return "";
    }
    }