1、使用pupeteer包自带的浏览器;
const browser = await puppeteer.launch({args: [
'--no-sandbox'
], ignoreDefaultArgs: [
'--enable-automation'
], headless: false});
2、使用本机的浏览器数据
--remote-debugging-port=9222
let wsKey = await axios.get('http://localhost:9222/json/version');
let browser = await puppeteer.connect({
browserWSEndpoint: wsKey.data.webSocketDebuggerUrl,
browserURL: wsKey.webSocketDebuggerUrl,
defaultViewport:null
});
Pupeteer常见错误:
问题类型:
net::ERR_HTTP2_PROTOCOL_ERROR
解决办法:
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36');