实现网站长截图

  • 下载node.js:https://nodejs.org/en/
  • 找到node安装的目录(跟本章内容无关,仅仅作为一个小知识)
which node

实现网站长截图

使用command+shift+G,在弹出的目录中填写/usr/local/bin/node就可以了

实现网站长截图

  • 新建一个目录,将目录拖入到iTerm,在iTerm中执行命令
npm i puppeteer
  • 然后将代码粘贴到新建的test.js内
//开启浏览器模式
const puppeteer = require('puppeteer');
puppeteer.launch({ headless: false,executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'}).then(function (browser)  {
    browser.newPage().then(function (page) {
            page.goto('https://www.baidu.com').then(function(){
                page.screenshot({path: 'test.png',fullPage:true}).then(function (data) {
                    //图片资源  自行处理
                    console.log(data)
                })
            })
    })
});

实现网站长截图

填自己的谷歌浏览器路径

实现网站长截图

  • 然后执行node test.js

就能跑起来了