Puppeteer chrome allow multiple file download

爱⌒轻易说出口 提交于 2019-12-11 05:32:18

问题


I am trying scrape one site will multiple pdf files. But after downloading the first one, chrome asks me to allow the site to download multiple files.

Can we allow this while launching the browser? This is the code which works once I allow manually and downloads all the files.

for(selector of selectors){
   await this.currentPage._client.send('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: downloadFilePath });
   await this.currentPage.waitFor(1000);
   await this.currentPage.evaluate(el => el.click(), selector);
   await this.currentPage.waitFor(1000 * 20);
}

回答1:


to avoid the allow multiple download popup use following code :

await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './'});

The downloadPath is the path where you want to download the files. You need to do it for each page you open.



来源:https://stackoverflow.com/questions/54919514/puppeteer-chrome-allow-multiple-file-download

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!