Puppeteer 反爬设置

const puppeteer  = require('puppeteer');
const devices        = require('puppeteer/DeviceDescriptors');
const ipad              = devices['iPad Pro landscape'];

async function anti_detection(page) {
    await page.emulate(iphone);
	await page.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36");
	await page.evaluateOnNewDocument(() => {
		delete navigator.__proto__.webdriver;
		Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5] });
		Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] });
		Object.defineProperty(navigator, 'platform', {
		   get: () => "Linux armxxxxx",
		   configurable: true
		});
		window.chrome = {
			app: {},
			runtime: {},
			getUserMedia: {}
		};
	});
	await page.setViewport({
		width: 1366,
		height: 1024,
		deviceScaleFactor: 1
	});
}


另外,headless = false 开启 GUI 图形界面伪装会更成功

你可能感兴趣的:(Puppeteer)