根據正則表示式匹配頁面中js和css檔案
阿新 • • 發佈:2019-01-09
// 匹配
List<string> srcList = new List<string>();
List<string> linkList = new List<string>();
// 匹配js檔案 string pattern = "<script[^>]*?src=\"([^>]*?)\"[^>]*?>"; MatchCollection mcs = Regex.Matches(html, pattern, RegexOptions.IgnoreCase); foreach (Match m in mcs) { srcList.Add(m.Groups[1].Value); } // 匹配css string patternCss = "<link[^>]*?href=\"([^>]*?)\"[^>]*?>"; mcs = Regex.Matches(html, patternCss, RegexOptions.IgnoreCase); foreach (Match m in mcs) { linkList.Add(m.Groups[1].Value); }