I\'ve been running the following code in order to download a csv
file from the website http://niftyindices.com/resources/holiday-calendar
:
I spent hours poring through this thread and Stack Overflow yesterday, trying to figure out how to get Puppeteer to download a csv file by clicking a download link in headless mode in an authenticated session. The accepted answer here didn't work in my case because the download does not trigger targetcreated
, and the next answer, for whatever reason, did not retain the authenticated session. This article saved the day. In short, fetch
. Hopefully this helps someone else out.
const res = await this.page.evaluate(() =>
{
return fetch('https://example.com/path/to/file.csv', {
method: 'GET',
credentials: 'include'
}).then(r => r.text());
});