C#在C#中通过url获取页面HTML文档L X Y2024-11-042026-02-16 这个简单直接上代码:1234567891011121314151617181920212223242526272829303132using System;using System.Net.Http;using System.Threading.Tasks;class Program{ static async Task Main() { Console.WriteLine("输入url地址:"); string url = Console.ReadLine(); using (HttpClient client = new HttpClient()) { try { HttpResponseMessage response = await client.GetAsync(url); string content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); } catch (HttpRequestException HRex) { Console.WriteLine("请求失败: " + HRex.Message); } catch (Exception ex) { Console.WriteLine("请求失败:" + ex.Message); } } Console.ReadLine(); }} 你猜的没错,这篇就是凑数的