入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

asp.net 获取html代码中图片的URL地址

创建时间:2017-02-07 投稿人: 浏览次数:1218
/// <summary> 
 /// 取得HTML中所有图片的 URL。  
 /// </summary>     
 /// <param name="sHtmlText">HTML代码</param>    
 /// <returns>图片的URL列表</returns>     
 public   string[] GetHtmlImageUrlList(string sHtmlText)  
 {       
      // 定义正则表达式用来匹配 img 标签       
       Regex regImg = new Regex(@"<img[^<>]*?src[s	
]*=[s	
]*["""]?[s	
]*(?<imgUrl>[^s	
"""<>]*)[^<>]*?/?[s	
]*>",RegexOptions.IgnoreCase);            
      // 搜索匹配的字符串        
      MatchCollection matches = regImg.Matches(sHtmlText);   
      int i = 0;      
      string[] sUrlList = new string[matches.Count];  
      // 取得匹配项列表          
      foreach (Match match in matches)     
      {   
         sUrlList[i++] = match.Groups["imgUrl"].Value;   
      }
     return sUrlList;     
 }

阅读更多
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像