您的位置:首页 > 运维架构 > 网站架构

10.用正则表达式 提取网页中的网站链接

2014-11-30 20:47 337 查看
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.IO;
  using System.Text.RegularExpressions;
  namespace q提取网页中的网站链接
  {
  class Program
  {
  static void Main(string[] args)
  {
  string str = File.ReadAllText("1.htm",Encoding.UTF8);
  MatchCollection ms = Regex.Matches(str, @"""(http://.+?)""");
  if (ms.Count!=0)
  {
  for (int i = 0; i < ms.Count;i++ )
  {
  if (ms[i].Success)
  {
  Console.WriteLine(ms[i].Groups[1].Value);
  }
  }
  }
  Console.ReadKey();
  }
  }
  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息