How can I download .pdf file from web with puppeteer? The site that I am using need cookies that must be imported before accessing.
I have already tried this:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://www.africau.edu/images/default/sample.pdf');
await page.setCookie({
"domain": "africau.edu",
"hostOnly": false,
"httpOnly": false,
"name": "test",
"path": "/",
"sameSite": "unspecified",
"secure": false,
"session": true,
"value": "testvalue",
"id": 1
});
await page.pdf({ path: 'sample.pdf', format: 'A4' });
await browser.close();
})();
Error that I get:
C:\Users\Khaniini\project\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:194
? new Error(`${response.errorText} at ${url}`)
^
Error: net::ERR_ABORTED at http://www.africau.edu/images/default/sample.pdf
at navigate (C:\Users\Khaniini\project\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:194:23)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async FrameManager.navigateFrame (C:\Users\Khaniini\project\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:170:21)
at async Frame.goto (C:\Users\Khaniini\project\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:589:16)
at async Page.goto (C:\Users\Khaniini\project\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:1089:16)
at async C:\Users\Khaniini\project\index.js:15:3
Thank you very much for your help!