下面是直接贴代码:

 

        #region  获得正文内容中的所有img标签的图片路径
        /// <summary>
        /// 获得正文内容中的所有img标签的图片路径
        /// </summary>
        /// <param name="strHTMLContnet">HTML内容</param>
        /// <returns></returns>
        public static List<string> GetImgsFromHTML(string strHTMLContnet)
        {
            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 matches = regImg.Matches(strHTMLContnet);
            int i = 0;
            // 取得匹配项列表      
            foreach (Match match in matches)
            {
                list.Add(match.Groups["imgUrl"].Value);
            }
            return list;
        }
        #endregion

 

相关文章:

  • 2022-01-11
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
猜你喜欢
  • 2021-07-15
  • 2021-05-15
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案