Girmiş oldğunuz sayfadaki cookileri kayıt etmek isterseniz bu durumda aşagıdaki kodu kullanabilirsiniz.
const { rejects } = require(‘assert’)
const { fstat, writeFileSync, writeFile } = require(‘fs’)
const { resolve } = require(‘path’)
const puppeteer = require(‘puppeteer’)
const fs = require(‘fs’).promises;
const sleep = (ms) => {
returnnewPromise((resolve, rejects) => {
setTimeout(() => {
resolve()
}, ms);
})
}
//save cookie function
const saveCookie = async (page) => {
constcookies = awaitpage.cookies();
constcookieJson = JSON.stringify(cookies, null, 2);
awaitfs.writeFile(‘cookies.json’, cookieJson);
}
//load cookie function
const loadCookie = async (page) => {
constcookieJson = awaitfs.readFile(‘cookies.json’);
constcookies = JSON.parse(cookieJson);
awaitpage.setCookie(…cookies);
}
const bot = async () => {
constbrowser = awaitpuppeteer.launch({
headless:false
});
constpage = awaitbrowser.newPage();
awaitpage.goto(‘https://www.google.com.tr’)
awaitsleep(5000)
constcookies = awaitpage.cookies();
console.log(cookies);
awaitsaveCookie(page);
}
bot()