我尝试将渲染的C#Web浏览器保存到我的硬盘。但它只保存html源,没有css或jquery js文件。我尝试了3种方法。
2.它只创建内容文本。没有html,css,js File.WriteAllText(@" text.txt",webBrowser5.Document.Body.InnerText);
3.它创建了更大的html文件,仍然没有css或jquery js文件 writer.Write(webBrowser5.DocumentText);
private void button1_Click(object sender, EventArgs e)
{
String source = ("viewsource.html");
StreamWriter writer = File.CreateText(source);
String myDocumentPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\111.html";
//It only creates only html file without any css, and jquery js files.
File.WriteAllText(myDocumentPath, webBrowser5.Document.Body.Parent.OuterHtml, Encoding.GetEncoding(webBrowser5.Document.Encoding));
//it only creates content text
File.WriteAllText(@"text.txt", webBrowser5.Document.Body.InnerText);
//It creates bigger html file, still no css or jquery js files
writer.Write(webBrowser5.DocumentText);
writer.Close();
}
答案 0 :(得分:0)
我在codeproject上找到了解决方案。 MHTML是要走的路。 http://www.codeproject.com/Articles/12977/Harvesting-Web-Content-into-MHTML-Archive
其他解决方案另存为图片: http://www.codeproject.com/Articles/6601/Capture-an-HTML-document-as-an-image