1、安装node环境
2、安装插件:npm install puppeteer 安装插件
3、创建抓取文件,如:index.js, 代码如下
const puppeteer = require('puppeteer');
async function test(url) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle2' });
const content = await page.content();
await browser.close();
return content;
}
test('https://baidu.com').then(content => {
console.log(content);
});