我正在尝试刮一个网站将多个pdf文件。但是在下载第一个文件后,chrome要求我允许该网站下载多个文件。
启动浏览器时我们可以允许吗?一旦我手动允许并下载所有文件,此代码便会起作用。
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);
}
答案 0 :(得分:2)
为避免允许多次下载弹出窗口,请使用以下代码:
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './'});
downloadPath是您要下载文件的路径。 您需要为打开的每个页面都这样做。