怎样复制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)

}

你可能感兴趣的:(怎样复制html阅读文件)