您的位置:首页 > Web前端 > HTML

c#从html中获取图片地址

2010-05-19 10:56 232 查看
using System.Text.RegularExpressions;
string ohtml = this.TextBox1.Text;
System.Text.RegularExpressions.MatchCollection m;
//提取字符串的图片
m = Regex.Matches(ohtml, "(<img).*?>");
for (int i = 0; i < m.Count; i++)
{
string ostr = m[i].ToString();
//提取图片的地址
System.Text.RegularExpressions.MatchCollection m2;
m2 = Regex.Matches(ostr, "(src=)['|/"].*?['/"]");
for (int j = 0; j < m2.Count; j++)
{
string strTemp = m2[j].ToString();
strTemp = strTemp.Replace("src=", "");
strTemp = strTemp.Replace("/"", "");
strTemp = strTemp.Replace("'", "");
Response.Write(strTemp+ "<br>");
}
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: