Lấy danh sách URL theo kiểu file trong html - A list of Uri in HTML


public List<Uri> FindLinks(string type, string html)
{
     var matches = Regex.Matches(
           html, string.Format(Pattern, type), RegexOptions.IgnoreCase | RegexOptions.Singleline);
     var urls = new List<Uri>();

     foreach (var hrefMatch in
     matches.Cast<Match>().Where(match => match.Groups.Count == 2).Select(match => match.Groups[1].Value).
     Select(link => HrefRegex.Match(link)).Where(hrefMatch => hrefMatch.Groups.Count == 2))
     {
          Uri url;
          var value = hrefMatch.Groups[1].Value;
          if (Uri.TryCreate(value, UriKind.Absolute, out url))
          {
               urls.Add(url);
          }
      }

      return urls;
}

Get danh sách URL theo kiểu file trong html - A list of Uri in HTML
Share To:

laptrinhvien

Post A Comment:

0 comments so far,add yours