puppeteer 设置cookies

const browser = await puppeteer.launch();
const url = 'https://example.com';
const page = await browser.newPage();
await page.goto(url);

const cookies = [{
'name': 'cookie1',
'value': 'val1'
},{
'name': 'cookie2',
'value': 'val2'
},{
'name': 'cookie3',
'value': 'val3'
}];

await page.setCookie(...cookies);
const cookiesSet = await page.cookies(url);
console.log(JSON.stringify(cookiesSet));
await browser.close();

你可能感兴趣的:(puppeteer 设置cookies)