例如:这个链接"http://news.xinhuanet.com/politics/2007-12/05/content_7200941.htm
"里面的照片是相对路径"<P align=center><IMG src="xin_1721204050818109272296.jpg" border=0></P>";
问题:怎样把src的值替换为自己的图片链接并写到数据库?
请高手给我思路,谢谢!
"里面的照片是相对路径"<P align=center><IMG src="xin_1721204050818109272296.jpg" border=0></P>";
问题:怎样把src的值替换为自己的图片链接并写到数据库?
请高手给我思路,谢谢!
pageload事件
string src="数据库的地址";
this.img1.innerhtml+="<IMG src=\""+src+"\" border=0> "
新闻是从其他媒体收集的,<p>标记和<img>标记都没有ID怎么办呢?
string s = "<img.*(?=src=[\"'](?<src>.+?)[\"']).*>";
Regex re = new Regex("(" + s + ")", RegexOptions.IgnoreCase);
// Response.Write(contentText);
MatchCollection mc = re.Matches(contentText);
foreach (Match m in mc)
{
string filesrc = m.Groups["src"].Value;
Response.Write(filesrc);
if (filesrc.ToLower().IndexOf("www.jobdll.com") < 0 && filesrc.ToLower().IndexOf("http:") >= 0)
{
int statint = filesrc.LastIndexOf("/") + 1;
string fileName = filesrc.Substring((statint < 0 ? 0 : statint));
WebClient wc = new WebClient();
wc.DownloadFile(filesrc, Server.MapPath("/") + "/user/" + dnsName.Value + "/photo/Pic/" + fileName);
contentText = contentText.Replace(filesrc, "/user/" + dnsName.Value + "/photo/Pic/" + fileName);
}
}
这个表达式希望对你有用
WebClient wc = new WebClient();
wc.DownloadFile(filesrc, Server.MapPath("/") + "/user/" + dnsName.Value + "/photo/Pic/" + fileName);
这个类是收集图片用的,代码就没发出来了
试试上面的正则