How to get the html of the current page?

I want to parse the html of the current page. How can I get the html of the current page for asp.net?

Thanks in advance.

+4
source share
3 answers

for the client side

In Internet Explorer

Right click on browser -> View Source

In firefox

Right click on browser β†’ View Source page

for the server side

You can override the way your page renders to capture the server side HTML source.

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 } 
+5
source

Override the Render method and call base.Render with your own HtmlWriter.

+2
source

Are you sure you want to parse HTML? This is a difficult business. If you don’t have to do this, I would avoid it using DOM methods on the client side (if the client-side solution is acceptable). If you do this a lot, you can consider jQuery , Prototype, or some other tool that will help.

+1
source

All Articles