Removing <script></script> block from returned html in C#
I am returning html contents (page layout) in a variable but want to remove <开发者_StackOverflow中文版;script>blabla</script>
tags and contents within these tags.
How can I do this?
You really need to parse the HTML.
Try using the Html Agility Pack which should make this pretty straightforward, for example:
HtmlDocument doc = new HtmlDocument();
doc.Load("HTMLPage1.htm");
foreach (var node in doc.DocumentNode.SelectNodes("//script"))
{
node.Remove();
}
精彩评论