在HTML中保存aspx页面 [英] save aspx page in html
本文介绍了在HTML中保存aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想知道如何将aspx页面保存到html文件中?
hi guys,
I want to know that how can i save a aspx page into html file?
推荐答案
// needs using System.Net and System.IO at the top of the page
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead("http://www.codeproject.com");
StreamReader reader = new StreamReader(data);
string html = reader.ReadToEnd();
data.Close();
reader.Close();
在Firefox或Google Chrome等网络浏览器中打开ASPX页面,然后选择另存为 - 您应该可以选择将页面保存为HTML文件。但是要明白这是渲染页面 - 任何动态的东西(需要运行ASP代码)都不再是动态的 - 你将拥有相当于页面的快照。
当你提出以编程方式执行此操作时,请尝试下面的代码:
Open the ASPX page in a web browser such as Firefox or Google Chrome, and choose 'Save As' - you should have the option to save the page as an HTML file. Understand however that this is the rendered page - anything dynamic (which requires ASP code to be run) will not be dynamic any longer - you'll have the equivalent of a snapshot of the page.
As you asked about doing this programatically, try the code below:
using (WebClient client = new WebClient ())
{
// Download as a file OR
client.DownloadFile("http://server/url.aspx", @"C:\result.html");
// Download as a string.
string htmlCode = client.DownloadString("http://server/url.aspx");
}
这篇关于在HTML中保存aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文