从html代码中获取Img标签
2013-01-11 19:52:57 来源:WEB开发网核心提示: /// <summary>/// 获取Img标签/// </summary>/// <param name="htmlText">截获到的html代码</param>/// <returns></returns>public
/// <summary>
/// 获取Img标签
/// </summary>
/// <param name="htmlText">截获到的html代码</param>
/// <returns></returns>
public static List<string> GetPadImg(string htmlText)
{
List<string> list = new List<string>();
Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
MatchCollection mc = regImg.Matches(htmlText);
foreach (Match m in mc)
{
list.Add(m.Groups["imgUrl"].Value); //获取Img标签
}
return list;
}