我正在使用puppeteer运行无头 chrome。登录后,我想保留会话 cookie 以供将来使用。有没有办法在 puppeteer 中保存和加载会话 cookie?
寻找类似的东西:
(async () => {
console.log('start -> ', true);
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setUserAgent(agent);
await page.setViewport({width: 1280, height: 699});
await page.goto('https://www.website.com/');
await login(); // custom method for log in
// here --->
const sessionCookies = await page.cookies.toJSON();
// and in another session --->
await page.setCookies(cookiesJson);
})();