using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;

namespace 抓取页面超链接
{
    class Program
    {
        static void Main(string[] args)
        {
            WebClient client = new WebClient();
            client.Encoding = Encoding.UTF8;
            string html = client.DownloadString("http://localhost:8080/test1.htm");
            //正则表达式提取字符串
            MatchCollection matches = Regex.Matches(html, "<[aA].*?\\s*href=\".+?\".*?>.+?</[aA]>");
            for (int i = 0; i < matches.Count; i++)
            {
                if (matches[i].Success)
                {
                    Console.WriteLine(matches[i].Value);
                    Console.WriteLine("========================================");
                }
            }
            Console.ReadKey();
        }
    }
}

相关文章:

  • 2021-12-18
  • 2022-01-29
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2021-08-14
  • 2022-02-07
  • 2022-02-07
  • 2022-12-23
  • 2022-02-07
  • 2022-01-08
相关资源
相似解决方案