StreamReader sr = new StreamReader("c://sina.htm",System.Text.Encoding.Default);
string strHtml = sr.ReadToEnd();
string strHtml = sr.ReadToEnd();
string p
=@"/<a.*href/s*=/s*(?:""(?<url>[^""]*)""|'(?<url>[^']*)'|(?<url>[^/>^/s]+)).*/>(?<title>[^/<^/>]*)/</.*/</a/>";
Regex reg = new Regex(p, RegexOptions.IgnoreCase | RegexOptions.Compiled);
MatchCollection ms = reg.Matches(strHtml);
foreach(Match m in ms)
{
Console.WriteLine("{0}/n{1}/n/n", m.Groups["title"].Value, m.Groups["url"].Value);
}
MatchCollection ms = reg.Matches(strHtml);
foreach(Match m in ms)
{
Console.WriteLine("{0}/n{1}/n/n", m.Groups["title"].Value, m.Groups["url"].Value);
}
博客展示了一段C#代码,通过StreamReader读取HTML文件内容,利用正则表达式匹配HTML中的链接信息,包括链接标题和URL,并将匹配结果输出。
582

被折叠的 条评论
为什么被折叠?



