前端之家收集整理的这篇文章主要介绍了
10.用正则表达式 提取网页中的网站链接,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
404_0@ using System;
@H_
404_0@ using System.Collections.Generic;
@H_
404_0@ using System.Linq;
@H_
404_0@ using System.Text;
@H_
404_0@ using System.IO;
@H_
404_0@ using System.Text.RegularExpressions;
@H_
404_0@ namespace q
提取网页中的网站
链接
@H_
404_0@ {
@H_
404_0@ class Program
@H_
404_0@ {
@H_
404_0@ static void Main(string[] args)
@H_
404_0@ {
@H_
404_0@ string str = File.ReadAllText("1.htm",Encoding.UTF8);
@H_
404_0@ MatchCollection ms = Regex.Matches(str,@"""(http://.+?)""");
@H_
404_0@ if (ms.Count!=0)
@H_
404_0@ {
@H_
404_0@ for (int i = 0; i < ms.Count;i++ )
@H_
404_0@ {
@H_
404_0@ if (ms[i].Success)
@H_
404_0@ {
@H_
404_0@ Console.WriteLine(ms[i].Groups[1].Value);
@H_
404_0@ }
@H_
404_0@ }
@H_
404_0@ }
@H_
404_0@ Console.ReadKey();
@H_
404_0@ }
@H_
404_0@ }
@H_
404_0@ }