1
我需要將網頁的輸出保存爲.html文件,以便稍後將其轉換爲圖像。下面是我使用的剝離不需要的成分,並只留下表的代碼:HtmlAgilityPack HtmlDocument.Save()行爲有所不同,具體取決於保存目錄
protected override void Render(HtmlTextWriter writer)
{
using (HtmlTextWriter htmlwriter = new HtmlTextWriter(new StringWriter()))
{
base.Render(htmlwriter);
string renderedContent = htmlwriter.InnerWriter.ToString();
string output = renderedContent.Replace(@"<input type=""submit"" name=""viewReport"" value=""View Report"" id=""viewReport"" />", "");
output = output.Replace(@"<input type=""submit"" name=""redoEdits"" value=""Redo Edits"" id=""redoEdits"" />", "");
output = output.Replace(@"<a href=""http://w3.td.com/td/intranet/tdweb""><img src=""Trends/TDBFGLogo5.gif"" alt=""TD Home"" title=""TD Home"" height=""40px"" width=""40px"" style=""float: left; border: none"" /></a>", "");
output = output.Replace(@"<hr style=""background-color: #8bb093; height: 30px; width: 100%; float: left"" />", "");
output = output.Replace(@"<h1>Network Operations Dashboard</h1>", "");
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(output);
HtmlNode node = doc.DocumentNode.SelectSingleNode("//select[@name='Archives']");
node.Remove();
node = doc.DocumentNode.SelectSingleNode("//ul[@id='mainNav']");
node.Remove();
string fileName = currDir + "\\dashboardTableOutput.html";
doc.Save(fileName);
writer.Write(renderedContent);
}
}
當我打電話:
doc.Save(currDir + "\\dashboardTableOutput.html");
我最終顯示這樣一個.html文件:
當我打電話
doc.Save(currDir + "\\" + reportDir + "\\dashboardTableOutput.html");
我最終顯示這樣一個.html文件:
與所有的佈局和圖形信息丟失。我想不出爲什麼改變我保存的目錄會有這種影響。
任何意見表示讚賞。
問候。