码迷,mamicode.com
首页 > Windows程序 > 详细

c# HTML中提取图片地址

时间:2016-04-07 09:31:54      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

public class HtmlHelper
????{
????????/// <summary>
????????/// HTML中提取图片地址
????????/// </summary>
????????public static List<string> PickupImgUrl(string html)
????????{
????????????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(html);
????????????List<string> lstImg = new List<string>();

????????????foreach (Match match in matches)
????????????{
????????????????lstImg.Add(match.Groups["imgUrl"].Value);
????????????}

????????????return lstImg;
????????}

????????/// <summary>
????????/// HTML中提取图片地址
????????/// </summary>
????????public static string PickupImgUrlFirst(string html)
????????{
????????????List<string> lstImg = PickupImgUrl(html);

????????????return lstImg.Count == 0 ? string.Empty : lstImg[0];
????????}
????}

c# HTML中提取图片地址

标签:

原文地址:http://www.cnblogs.com/qq260250932/p/5362107.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!