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

问题描述 投票:0回答:1

我正在处理访问页面的测试用例,获取页面源并将其保存到 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>

html regex robotframework
1个回答
2
投票

这是我的尝试:

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

正则表达式住在这里。

解释:

#   <script              # match the start of the tag
#   [^>]*>               # match anything till the ">" character
#   [^\0]*?<\/script>    # match anything (not null) till the closing tag
© www.soinside.com 2019 - 2024. All rights reserved.