保存到硬盘 [英] saving to the hard drive

查看:94
本文介绍了保存到硬盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用c#

推荐答案

使用WebClient提取页面和System.IO.File.WriteAllText(filename, html)保存.

或者只是:

Use a WebClient to fetch the page and System.IO.File.WriteAllText(filename, html) to save it.

Or just:

public static void DownloadWebsite(string url, string filename)
{
    using (WebClient client = new WebClient())
    {
        Stream data = client.OpenRead(url);
        StreamReader reader = new StreamReader(data);
        string s = reader.ReadToEnd();
        data.Close();
        reader.Dispose();
        System.IO.File.WriteAllText(filename, s);
    }
}


DownloadWebsite("http://www.codeproject.com", @"D:\myFile.txt");



如果您想下载完整的网站(包括图像,javascript,css等),则需要做更多的工作.然后,您应该看一下这篇文章:使用本机.NET代码将任何URL转换为MHTML存档 [



If you want to download the comlete site (including images, javascripts, css etc) it''s a lot more work. Then you should take a look at this article: Convert any URL to a MHTML archive using native .NET code[^]


这篇关于保存到硬盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆