Puppeteer Chrome允许下载多个文件 [英] Puppeteer chrome allow multiple file download

查看:242
本文介绍了Puppeteer Chrome允许下载多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试刮取一个站点将多个pdf文件。但是在下载第一个文件后,chrome要求我允许该网站下载多个文件。

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);
}


推荐答案

以避免允许多次下载弹出窗口使用以下代码:

to avoid the allow multiple download popup use following code :

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

downloadPath是您要下载文件的路径。
您需要为打开的每个页面都这样做。

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

这篇关于Puppeteer Chrome允许下载多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆