原理:把整个网页中元素的样式全部改为内连样式。
使用方式:
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 = $('<div>').append($(select).clone()).html();
  console.log(content)
}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐