删除<脚本>使用C#HTML页面标签脚本、标签、页面、LT

2023-09-04 02:38:55 作者:雪殤

<html>
<head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
            if (window.self === window.top) { $.getScript("Wing.js"); }
        </script>
</head>
</html>

有没有办法在C#修改上面显示HTML文件,并转换成如下

Is there a way in C# to modify the above shown html file and convert it into format shown below

<html>
<head>
</head>
</html>

基本上我的目标是消除所有添加到HTML页面的JavaScript。不知道什么应该是修改这些html文件的最好方法。我想这样做编程,因为有数百个文件,这需要修改

Basically my goal is to remove all the javascript added to the html pages. Don't know what should be the best way to modify these html files. I want to do it programmatically as there are hundreds of files which needs modification

推荐答案

它可以使用正则表达式来完成:

It can be done using regex:

Regex rRemScript = new Regex(@"<script[^>]*>[\s\S]*?</script>");
output = rRemScript.Replace(input, "");