C# WebClient.DownloadString() 获取特定部分

本文关键字:定部 获取 WebClient DownloadString | 更新日期: 2023-09-27 18:36:24

我想从网站下载一个特定的字符串,但我不确定如何以最佳方式实现它。

现在我是这样做的:

using (WebClient webClient = new WebClient())
{
    string htmlString = webClient.DownloadString(url);
    string encoding = WebUtility.UrlDecode(htmlString);
    Console.WriteLine(encoding);
}

但是,这会将整个网页作为字符串返回,我可以以某种方式只下载 URL 的特定部分吗?

C# WebClient.DownloadString() 获取特定部分

如果 Web 服务器支持字节服务(接受范围标头),那么您可以访问文档的一部分。

https://en.wikipedia.org/wiki/Byte_servinghttps://msdn.microsoft.com/library/7fy67z6d(v=vs.100).aspxhttps://blogs.msdn.microsoft.com/webdev/2012/11/23/asp-net-web-api-and-http-byte-range-support/