如何删除< script>使用C#从HTML页面标记? [英] How to remove <script> tags from an HTML page using C#?
本文介绍了如何删除< script>使用C#从HTML页面标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<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 HTML file and convert it into this format:
<html>
<head>
</head>
</html>
基本上我的目标是从HTML页面中删除所有JavaScript。我不知道什么是修改HTML文件的最佳方法。我想以编程方式进行,因为有数百个文件需要修改。
Basically my goal is to remove all the JavaScript from the HTML page. I don't know what is be the best way to modify the HTML files. I want to do it programmatically as there are hundreds of files which need to be modified.
推荐答案
可以使用正则表达式完成:
It can be done using regex:
Regex rRemScript = new Regex(@"<script[^>]*>[\s\S]*?</script>");
output = rRemScript.Replace(input, "");
这篇关于如何删除< script>使用C#从HTML页面标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文