<a HREF="http://blog.photo.sina.com.cn/showpic.html#url=http://static8.photo.sina.com.cn/orignal/50d70f89t6d941038b767&amp;690" TARGET="_blank"><img STYLE="MAx-WiDTH: 500px" SRC="http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&amp;690" /></A>
图像地址是:http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&amp;690 如何自动的加上.jpg 成:
<a HREF="http://blog.photo.sina.com.cn/showpic.html#url=http://static8.photo.sina.com.cn/orignal/50d70f89t6d941038b767&amp;690" TARGET="_blank"><img STYLE="MAx-WiDTH: 500px" SRC="http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&amp;690.jpg" /></A>

解决方案 »

  1.   

    通过正则替换图片添加jpg
    参考
      

  2.   

    upjf
    参考:
    http://topic.csdn.net/u/20080420/19/f36fb7c0-b8a5-4d67-837c-9dc3a96907b8.html
      

  3.   

    body中添加 onload="AddtheJPG()"function AddtheJPG()
    {
        var imgsrc="http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&amp;690" +".jpg"document.getElementById("你图片的id").src= imgsrc;
    }
    如果是多个图片 可以规定 图片的id="myimage"+i  获取页面的图片数,根据id,给图片赋地址。
      

  4.   

    新浪图片的抓取?做过
    &amp;一定要替换,否则,无法显示图片,我为这个郁闷了好久 。  public static string SaveImages(string account, string content,DateTime time)
            {
                string path = Path.Combine(Config.GetConfig().BlogAlbumPath, account);
                if (!path.EndsWith("\\"))
                    path += "\\";
                string cPath = string.Format("{0}_{1}_{2}", time.Year, time.Month, time.Day);
                path = string.Format("{0}{1}\\", path, cPath);            if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string urlPath = string.Format("{0}/{1}/{2}/",Config.GetConfig().BlogAlbumUrl,account,cPath);
               // Regex r = new Regex("<img.*?src\\s*=\"(?<src>[^\"]*)[^>]*>", RegexOptions.IgnoreCase|RegexOptions.Singleline);
                Regex r=new Regex("<a\\s+href=\"(?<url>.*?photo\\.blog\\.sina\\.com\\.cn/showpic\\.html.*?)\".*?<img.*?src\\s*=\"(?<src>[^\"]*)[^>]*>.*?</a>",RegexOptions.IgnoreCase|RegexOptions.Singleline);
                string str =content;
               
                MatchCollection ms = r.Matches(content);
               foreach (Match m in ms)
                { 
                    if(m.Success)
                    {
                      string src=m.Groups["src"].Value;
                      string url = m.Groups["url"].Value;
                      string name = Path.GetFileName(src).Replace("&amp;","&");
                      string imgUrl = string.Empty;
                      if (!string.IsNullOrEmpty(name))
                      {
                          string savePath = Path.Combine( path, name);
                          string newExt = string.Empty;
                          Download(src, savePath, out newExt);
                          string ext = Path.GetExtension(name);                      if (string.IsNullOrEmpty(ext))
                          {
                              string newName = string.Format("{0}{1}", savePath, newExt);
                              if (!File.Exists(newName))
                              {
                                  File.Move(savePath, newName);
                              }
                              savePath = newName;
                              imgUrl = string.Format("{0}{1}{2}", urlPath, name,newExt);
                          }
                          else
                          {
                              imgUrl = string.Format("{0}{1}", urlPath, name);
                          }
                          str = str.Replace(src, imgUrl);
                          str = str.Replace(url, imgUrl);
                      }
                    }
                }
                
                return str;
            }
      

  5.   

    5楼兄弟,运行时,有如下提示,请问怎么改正正则?应用程序中的服务器错误。
    --------------------------------------------------------------------------------正在分析“ <a\s+href="(? <url>.*?photo\.blog\.sina\.com\.cn/showpic\.html.*?)".*? <img.*?src\s*="(? <src>[^"]*)[^>]*>.*? </a>”- 无法识别的分组构造。 
      

  6.   

     <a\s+href="(?<url>.*?photo\.blog\.sina\.com\.cn/showpic\.html.*?)".*? <img.*?src\s*="(?<src>[^"]*)[^>]*>.*? </a>?和<中间有空格
      

  7.   

    还是不行,,这个问题搞了24小时了,救救我:string ohtml = @"<img SRC=""http://zi.csdn.net/73560xly_2"" WIDTH=""500"" BORDER=""0""></IMG><img SRC=""http://zi.csdn.net/a.gif"" WIDTH=""500"" BORDER=""0""></IMG>";        string result = Regex.Replace(ohtml.ToLower(), @"(?is)(?<=<img\b(?:(?!src=).)*src=(['""]?))[^'""\s]*/([^/.]+\.[a-z]+)(?=\1)", "http://www.mysite.com/up/$2.jpg");        Response.Write(result);这样替换后,输出是:<img src="http://zi.csdn.net/73560xly_2" width="500" border="0"></img><img src="http://www.mysite.com/up/a.gif.jpg" width="500" border="0"></img>
    其中,其中第一张图还是没被替换,,郁闷死了!
      

  8.   

    http://zi.csdn.net/73560xly_2就是这个图,我要为这个地址加上.jpg 成为http://zi.csdn.net/73560xly_2.jpg
      

  9.   

    string ohtml = @"<img SRC=""http://zi.csdn.net/73560xly_2"" WIDTH=""500"" BORDER=""0""></IMG><img SRC=""http://zi.csdn.net/a.gif"" WIDTH=""500"" BORDER=""0""></IMG>";        string result = Regex.Replace(ohtml.ToLower(), @"(?is)(?<=<img\b(?:(?!src=).)*src=(['""]?))[^'""\s]*/([^/.]+\.[a-z]+)(?=\1)", "http://www.mysite.com/up/$2");        Response.Write(result);
      

  10.   

    <img SRC=""http://zi.csdn.net/73560xly_2"" WIDTH=""500"" BORDER=""0""></IMG><img SRC=""http://zi.csdn.net/a.gif"" WIDTH=""500"" BORDER=""0""></IMG>正则
    (?is)(?<=<img\b(?:(?!src=).)*src=(['""]?))[^'""\s]*/([^/.]+\.[a-z]+)(?=\1)仅能得出http://zi.csdn.net/a.gif而不能得出http://zi.csdn.net/73560xly_2,所以现在没法替换,正确的正则应怎么写?
      

  11.   

    11楼兄,你给的正则没有变化啊,还是取不出http://zi.csdn.net/73560xly_2这个地址,只能取出有后缀的地址
      

  12.   

    string ohtml = @" <img SRC=""http://zi.csdn.net/73560xly_2"" WIDTH=""500"" BORDER=""0""> </IMG> <img SRC=""http://zi.csdn.net/a.gif"" WIDTH=""500"" BORDER=""0""> </IMG>";
            string result = Regex.Replace(ohtml.ToLower(), @"(?is)((?<=src=\"?)[^"]*)", "http://www.mysite.com/up/$2.jpg");这样也行的
      

  13.   

      string result = Regex.Replace(ohtml.ToLower(), @"(?is)((? <=src=\""?)[^""]*)", "http://www.mysite.com/up/$2.jpg"); 应该是双引号
      

  14.   

    结贴后问题才出现,虽然输出是http://zi.csdn.net/a.gif 和 http://zi.csdn.net/73560xly_2,但用户到程序当中,却替换不了,真是超郁闷,另开贴提问吧:)