I had to request the same webpage twice to get the cookies in the 1st request and use it in the 2nd request in the following example.
Could anybody show me the code to save the cookies in one puppeteer session and load it in another session so that there is no need to request the same webpage twice in the 2nd session? Thanks.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.genecards.org/cgi-bin/carddisp.pl?gene=BSCL2');
await page.goto('https://www.genecards.org/cgi-bin/carddisp.pl?gene=BSCL2');
const linkHandlers = await page.$x("//div[@id='enhancers']//a[@data-track-event='Table See-All']");
if (linkHandlers.length > 0) {
const [response] = await Promise.all([
page.waitForResponse(response => response.url().includes('/gene/api/data/Enhancers')),
linkHandlers[0].click()
]);
const resp_text = await response.text();
console.log(resp_text);
} else {
throw new Error("Link not found");
}
await browser.close();
})();