[英]How to save webpage with css and js files from C# webbrowser?
我试图将呈现的 C# 网络浏览器保存到我的硬盘中。 但它只保存 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();
}
我在 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.