puppeteer, 设置浏览器的设备案例。
const puppeteer = require('puppeteer');
const devices = require('puppeteer/DeviceDescriptors');
const iPhone = devices['iPhone 6'];
(async () => {
const browser = await (puppeteer.launch({
//设置超时时间
timeout: 15000,
//如果是访问https页面 此属性会忽略https错误
ignoreHTTPSErrors: true,
devtools: true,
headless: false,
args: ['--no-sandbox']
}));
const page = await browser.newPage();
// 设置模拟iphone6
await page.emulate(iPhone);
// 打开m站首页
await page.goto('https://m.leka.club/sub_card/card_purcotton.html');
// ...
})();
安装puppteer 依赖
npm config set puppeteer_download_host=https://npm.taobao.org/mirrors
或者用cnpm