Warm tip: This article is reproduced from serverfault.com, please click

node.js-PDF不随木偶一起下载

(node.js - PDF doesn't download with puppeteer)

发布于 2020-11-26 14:30:59

因此,我正在尝试下载一个这样的pdf文件,该文件会在弹出窗口中打开。

在此处输入图片说明

在此处使用此代码获取弹出窗口并将其下载到“ ./”。

const popUp = await popUpPromise
        await popUp.waitFor(5000)
        // await popUp.waitForSelector('.content')
        const pdf = await popUp.$$eval('html', e => e)
        await console.log(pdf)
        await popUp._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './'})

但是,不仅下载不正常,而且弹出的html返回空。

Questioner
LGimenez
Viewed
0
Brewha 2020-12-03 05:34:51

为了从弹出窗口下载pdf,一旦弹出窗口加载,你将需要模拟按ctrl-s的操作。它应该下载到你的“下载行为”设置中的指定文件夹中。尝试使用await page.type()await page.press()