问题
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