// cnpm i puppeteer
const puppeteer = require('puppeteer');
// or
// cnpm i puppeteer-core
const puppeteer = require('puppeteer-core');
const browser = await puppeteer.launch();
//or
const browser = await puppeteer.launch({
executablePath: 'C:/Program Files (x86)/Google/Chrome/Application/chrome',
headless: false
});
let page = await browser.newPage();
await page.goto('https://www.baidu.com');
await page.waitForNavigation('load');
// page.evaluate() 进入浏览器操作页面(console)
const result = await page.evaluate(( ) => {
...
return result
});
var login = await page.$('.login')
await login.click()
await page.tracing.start({path: './trace.json'});
await page.goto('https://www.google.com');
await page.tracing.stop();
网友评论