Googleアカウントとかでログイン後にスクレイピングなど
const browser = await puppeteer.launch({
headless: false,
defaultViewport: viewport,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const pages = await browser.pages();
const page = pages[0];
let cookieFile = "cookies.txt";
const cookies = JSON.parse(fs.readFileSync(cookieFile, 'utf-8'));
await page.setCookie(...cookies);
await page.goto(url, {
waitUntil: 'domcontentloaded',
timeout:0
});
await page.waitFor(6000);
const afterCookies = await page.cookies();
fs.writeFileSync(cookieFile, JSON.stringify(afterCookies));
await browser.close();
コメント