dotnetcore爬虫(一)简单获取页面信息

使用前需要引用下面这个包

using System.Net.Http;

我们就不多讲理论了,直接拿出代码,尝试尝试就知道需要用到什么知识了。

毕竟实践是检验真理的唯一标准。

using System;
using System.Net.Http;

namespace dotnetcoreHttpClient
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpClient client = new HttpClient(new HttpClientHandler());
            //获取我们当前网站的dom
            var html = client.GetStringAsync("https://blog.csdn.net/qq_36051316/article/details/84380024").Result.ToString();
            Console.WriteLine("输出网站内容:");
            Console.WriteLine("================华丽分割线==================");
            System.Console.WriteLine(html);
        }
    }
}

你可能感兴趣的:(dotnet,core)