-1

What I want to do is to strip away all JavaScript and CSS snippets from an HTML page and get pure HTML code. How can I do it correctly?

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
user979432
  • 11
  • 4
  • There is no simple way to do this as far as i understand, you will just have to go through your code, see what it does, then rewrite it – Ibu Dec 20 '11 at 23:59
  • I think since all css and js will be tagged by the `style` or `script` tag, you can just run through the html file, remove anything between, and including `` and `` – Indranil Dec 21 '11 at 00:04

3 Answers3

2

You could always use the Html Agility Pack to try to parse the HTML, remove the offending script/style nodes, and output the rest.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
0

Another similar post with a popular answer Using C# regular expressions to remove HTML tags

An alternative, perhaps not as elegant but safer option would be to pass the html to a third party service and interpret the results

Community
  • 1
  • 1
CBusBus
  • 2,321
  • 1
  • 18
  • 26
0

thanks, unfortunatelly it's possible to put JS and CSS to HTML without using HTML tags. You can do it with HTML style attribute for CSS, and You can bind JS to event for a button for example with a attribute too. I thought there is elegant, automatic way to clean HTML... :/

user979432
  • 11
  • 4