提取页面中的style标签内容

脚本

const {exec} = require('child_process');
const iconv = require('iconv-lite');

let str = `

<head>
<style>
* {
  padding: 0;
  margin: 0;
}
</style>
<style>
li {
  list-style: none;
}
</style>
</head>

`

let arr = []

str.replace(/<style.*>(\n|.)*<\/style>/gim, s => {
  arr.push(s)
})

let arr2 = []

for (let i = 0, len = arr.length; i < len; i++) {
  let v = arr[i]
  v = v.replace(/<style.*>/gim, '')
  v = v.replace(/<\/style>/gim, '')
  arr2.push(v)
}

let str2 = arr2.join("\n")

exec('clip').stdin.end(iconv.encode(str2.trim(), 'gbk'));
console.log('===复制成功===', new Date().toLocaleString())

结果

* {
  padding: 0;
  margin: 0;
}


li {
  list-style: none;
}

本文地址

https://www.cnblogs.com/stumpx/p/15161107.html

===

posted @ 2021-08-19 12:01  stumpx  阅读(64)  评论(0编辑  收藏  举报