怎样复制html阅读文件,如何快速复制一个网站内容和样式

原理:把整个网页中元素的样式全部改为内连样式。

使用方式:

1、打开浏览器控制台。

2、运行以下脚本。

3、复制控制台输出。

4、新建一个html 文件,将复制的内容copy 到这个文件中。

5、浏览器中打开html文件就可看到该网站内容。

注意:该方式复制的只是静态样式,不包含功能。

let select = 'body'

if(!window.$ || !window.jQuery) {

var x = document.createElement("SCRIPT");

x.setAttribute('src','https://code.jquery.com/jquery-2.2.4.min.js')

document.body.appendChild(x);

setTimeout(startRenderEl, 2000)

} else {

startRenderEl()

}

function startRenderEl() {

let styles = [

'color','background','width',

'height','fontSize','lineHeight', 'margin',

'padding','position', 'float','right',

'bottom','top','left', 'display','border',

'borderTop','borderBottom','borderLeft','borderRight',

'cursor','overflow','boxSizing','borderColor',

'borderRadius','textDecoration','listStyle',

'textAlign'

]

dealItemEl(select)

$(select+' *').each((index, el) => {

dealItemEl(el)

})

function dealItemEl(el) {

if (typeof el === 'string') {

el = $(el)

}

if (el instanceof jQuery) {

el = el[0]

}

let styleObj = window.getComputedStyle(el)

styles.forEach(v => {

if (styleObj[v]) {

$(el).css(v, styleObj[v])

}

})

}

let content = $('

').append($(select).clone()).html();

console.log(content)

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值