【发布时间】:2015-09-02 13:35:19
【问题描述】:
我想使用 css 或 xpath 选择器删除 style 和 script 标签及其内容。
这是一个 HTML 示例:
<html>
<head>
<title>test</title>
<style>
// style
</style>
<script>
/* some script */
</script>
</head>
<body>
<p>text</p>
<script>
/* some script */
</script>
<div>foo</div>
</body>
</html>
我想得到这样的 HTML:
<html>
<head>
<title>test</title>
</head>
<body>
<p>text</p>
<div>foo</div>
</body>
</html>
我认为我可以使用此代码获得不包含 <script> 标记的 HTML,但不知何故,该代码仅复制了 HTML。
doc = Nokogiri::HTML(open("foo.text"))
doc.css(":not(script)").to_html
如何启用我想要的行为?
【问题讨论】:
标签: javascript css ruby xpath nokogiri