麻烦高手给个把图片相对地址转换成绝对地址的代码 我就是已整段HTML代码,在编辑器拿出来的,你拼我看看,我需要的是一个正则表达式 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string str="你的内容";string result=str.IndexOf("http://www.xxxxx.com") > -1 ? str : str.Replace("\"/", "\"http://www.xxxxx.com/"); public static string ConvertToAbsolute(string strValue,string baseUrl) { if(strValue=="") return ""; string strRef = @"(src|href)[ ]*=[ ]*[""']*[^""'#>]+[""']*"; MatchCollection matches = new Regex(strRef,RegexOptions.IgnoreCase).Matches(strValue); foreach(Match match in matches) { strRef = match.Value.Substring(match.Value.IndexOf('=')+1).Trim('"', '\'', '#', ' ', '>'); if(strRef.IndexOf("..") != -1 || strRef.StartsWith("/") || strRef.StartsWith("./") || !strRef.StartsWith("http://") ) { string absRef = new Uri(new Uri(baseUrl), strRef).AbsoluteUri; strValue=strValue.Replace(strRef,absRef); } } return strValue; }之前写的采集器的代码 我就是已整段HTML代码,在编辑器拿出来的,你拼我看看,我需要的是一个正则表达式不是需要这样的 public static string ConvertToAbsolute(string strValue,string baseUrl) { if(strValue=="") return ""; string strRef = @"(src|href)[ ]*=[ ]*[""']*[^""'#>]+[""']*"; MatchCollection matches = new Regex(strRef,RegexOptions.IgnoreCase).Matches(strValue); foreach(Match match in matches) { strRef = match.Value.Substring(match.Value.IndexOf('=')+1).Trim('"', '\'', '#', ' ', '>'); if(strRef.IndexOf("..") != -1 || strRef.StartsWith("/") || strRef.StartsWith("./") || !strRef.StartsWith("http://") ) { string absRef = new Uri(new Uri(baseUrl), strRef).AbsoluteUri; strValue=strValue.Replace(strRef,absRef); } } return strValue; }之前写的采集器的代码没去测试,因为我找到了Regex.Replace(detail, @"(?is)( src=['|""]*)(?!http)/*([^'""]+)", "$1" + url + "/$2");还是谢谢你! 像我这样该如何验证验证码 ado.net连接数据库 winform中的窗体改变不了啦? 显示问题 如何禁止在单击组合框右边向下的箭头时不显示下拉列表? SQL连接语句中的server=? 如何执行类似VB的Shell呀? 请教下用OleDb怎么访问Sql 2000数据库表的primary key? MDI的父子窗口! 非常急,有谁能解决,有几天了 HttpClient 和 WebClient如何实现Get和Post请求 Panel传值问题
string str="你的内容";
string result=str.IndexOf("http://www.xxxxx.com") > -1 ? str : str.Replace("\"/", "\"http://www.xxxxx.com/");
{
if(strValue=="")
return ""; string strRef = @"(src|href)[ ]*=[ ]*[""']*[^""'#>]+[""']*";
MatchCollection matches = new Regex(strRef,RegexOptions.IgnoreCase).Matches(strValue);
foreach(Match match in matches)
{
strRef = match.Value.Substring(match.Value.IndexOf('=')+1).Trim('"', '\'', '#', ' ', '>');
if(strRef.IndexOf("..") != -1 || strRef.StartsWith("/") || strRef.StartsWith("./") || !strRef.StartsWith("http://") )
{
string absRef = new Uri(new Uri(baseUrl), strRef).AbsoluteUri;
strValue=strValue.Replace(strRef,absRef);
}
}
return strValue;
}之前写的采集器的代码
不是需要这样的
{
if(strValue=="")
return ""; string strRef = @"(src|href)[ ]*=[ ]*[""']*[^""'#>]+[""']*";
MatchCollection matches = new Regex(strRef,RegexOptions.IgnoreCase).Matches(strValue);
foreach(Match match in matches)
{
strRef = match.Value.Substring(match.Value.IndexOf('=')+1).Trim('"', '\'', '#', ' ', '>');
if(strRef.IndexOf("..") != -1 || strRef.StartsWith("/") || strRef.StartsWith("./") || !strRef.StartsWith("http://") )
{
string absRef = new Uri(new Uri(baseUrl), strRef).AbsoluteUri;
strValue=strValue.Replace(strRef,absRef);
}
}
return strValue;
}之前写的采集器的代码没去测试,因为我找到了
Regex.Replace(detail, @"(?is)( src=['|""]*)(?!http)/*([^'""]+)", "$1" + url + "/$2");
还是谢谢你!