node.js - Puppeteer chrome 允许多个文件下载
问题描述
我正在尝试抓取一个站点将多个 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);
}
解决方案
为避免允许多次下载弹出窗口,请使用以下代码:
await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './'});
downloadPath 是您要下载文件的路径。您需要为打开的每个页面执行此操作。
推荐阅读
- kubernetes - Kubernetes,Fluentd:匹配“stdout”日志
- three.js - three.js - 如何围绕lookAt(object)和相机位置之间的线旋转相机
- antlr4 - 在词法分析器中定义时,解析器警告中标记的隐式定义
- r - 在 R 中的值向量后添加百分比,并用单引号将每个值括起来
- forms - 如何使用 Symfony 创建带有可变字段的表单?
- c++ - 如果我们只是传递变量,为什么通过指针函数起作用请指导
- matlab - 使用 matlab 的 spmd 计算简单的三重积分给了我不正确的解决方案,对我做错了什么有什么想法吗?
- javascript - 如何在ant design Form的Form.Item中迭代添加Form.Item
- python - Python sql 查询占用的内存是表大小的 3 倍?
- php - 任何检查base64代码有什么问题的方法