Robot Framework - 如何使用 Remove String Using Regexp 关键字从 html 中删除 javascript 标签

Robot Framework - how to strip out javascript tags from html using Remove String Using Regexp keyword

我正在处理访问页面的测试用例,获取页面源并将其保存到 html 文件中。在保存源代码之前,我需要删除所有 javascript 从“”到“”。我浏览了大量的在线资源并提出了 <script type="text/javascript">([\s\S]*?)<\/script> 但我输入到测试用例中的正则表达式语法似乎不起作用。有人有什么建议吗?

更多信息: 页面源代码包含许多 JavaScript 实例并跨越多行,因此我认为我需要在表达式前加上 (ims) 前缀。在我上面的解决方案中,您还会看到我已经转义了反斜杠,因为我在某处读到它是必要的。

源代码示例

<html>
<script type="text/javascript">
some multiline javascript
  </script>
<script type="text/javascript"> some single line javascript  </script>
<body>
body content
</body>
<script type="text/javascript">
some more javascript
</script>

这是我的尝试:

"<script[^>]*>[^[=10=]]*?<\/script>", gi

Regex live here.

解释:

#   <script              # match the start of the tag
#   [^>]*>               # match anything till the ">" character
#   [^[=11=]]*?<\/script>    # match anything (not null) till the closing tag

希望对您有所帮助。