开发者

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜