【问题标题】:C# code to download a website with images [closed]用于下载带有图像的网站的 C# 代码 [关闭]
【发布时间】:2021-05-17 21:02:59
【问题描述】:

给定一个 URL,下载该网页内容的最有效代码是什么?我只考虑 HTML、CSS 和图像。

【问题讨论】:

  • 你好@janik313。你有什么具体的问题吗?

标签: c# html download


【解决方案1】:
using System.Net;

using (WebClient client = new WebClient ()) // WebClient class inherits IDisposable
{
    client.DownloadFile("http://yoursite.com/page.html", @"C:\localfile.html");

    // Or you can get the file content without saving it
    string htmlCode = client.DownloadString("http://yoursite.com/page.html");
}

【讨论】:

  • 请参阅Remarks 关于 WebClient。请改用 HttpClient。
猜你喜欢
  • 2020-03-18
  • 1970-01-01
  • 2012-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多