我想解析当前页面的html。如何在asp.net中获取当前页面的html?
提前谢谢。
发布于 2009-10-19 12:36:35
客户端的
在Internet explorer中
右键单击浏览器-->查看源代码
在firefox中
右键单击浏览器-->查看页面源代码
服务器端的
您可以重写页面的render方法来捕获服务器端的HTML源代码。
protected override void Render(HtmlTextWriter writer)
{
// setup a TextWriter to capture the markup
TextWriter tw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(tw);
// render the markup into our surrogate TextWriter
base.Render(htw);
// get the captured markup as a string
string pageSource = tw.ToString();
// render the markup into the output stream verbatim
writer.Write(pageSource);
// remove the viewstate field from the captured markup
string viewStateRemoved = Regex.Replace(pageSource,
"<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\".*?\" />",
"", RegexOptions.IgnoreCase);
// the page source, without the viewstate field, is in viewStateRemoved
// do what you like with it
}发布于 2009-10-19 12:35:48
覆盖Render方法并使用您自己的HtmlWriter调用base.Render。
https://stackoverflow.com/questions/1588431
复制相似问题