如
<a HREF="http://blog.photo.sina.com.cn/showpic.html#url=http://static8.photo.sina.com.cn/orignal/50d70f89t6d941038b767&690" TARGET="_blank"><img STYLE="MAx-WiDTH: 500px" SRC="http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&690" /></A>
图像地址是:http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&690 如何自动的加上.jpg 成:
<a HREF="http://blog.photo.sina.com.cn/showpic.html#url=http://static8.photo.sina.com.cn/orignal/50d70f89t6d941038b767&690" TARGET="_blank"><img STYLE="MAx-WiDTH: 500px" SRC="http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&690.jpg" /></A>
<a HREF="http://blog.photo.sina.com.cn/showpic.html#url=http://static8.photo.sina.com.cn/orignal/50d70f89t6d941038b767&690" TARGET="_blank"><img STYLE="MAx-WiDTH: 500px" SRC="http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&690" /></A>
图像地址是:http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&690 如何自动的加上.jpg 成:
<a HREF="http://blog.photo.sina.com.cn/showpic.html#url=http://static8.photo.sina.com.cn/orignal/50d70f89t6d941038b767&690" TARGET="_blank"><img STYLE="MAx-WiDTH: 500px" SRC="http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&690.jpg" /></A>
参考
参考:
http://topic.csdn.net/u/20080420/19/f36fb7c0-b8a5-4d67-837c-9dc3a96907b8.html
{
var imgsrc="http://static8.photo.sina.com.cn/bmiddle/50d70f89t6d941038b767&690" +".jpg"document.getElementById("你图片的id").src= imgsrc;
}
如果是多个图片 可以规定 图片的id="myimage"+i 获取页面的图片数,根据id,给图片赋地址。
&一定要替换,否则,无法显示图片,我为这个郁闷了好久 。 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("&","&");
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;
}
--------------------------------------------------------------------------------正在分析“ <a\s+href="(? <url>.*?photo\.blog\.sina\.com\.cn/showpic\.html.*?)".*? <img.*?src\s*="(? <src>[^"]*)[^>]*>.*? </a>”- 无法识别的分组构造。
其中,其中第一张图还是没被替换,,郁闷死了!
(?is)(?<=<img\b(?:(?!src=).)*src=(['""]?))[^'""\s]*/([^/.]+\.[a-z]+)(?=\1)仅能得出http://zi.csdn.net/a.gif而不能得出http://zi.csdn.net/73560xly_2,所以现在没法替换,正确的正则应怎么写?
string result = Regex.Replace(ohtml.ToLower(), @"(?is)((?<=src=\"?)[^"]*)", "http://www.mysite.com/up/$2.jpg");这样也行的