我想获取下载内容(缓冲区),然后将数据存储在我的 S3 帐户中。到目前为止我还没有找到一些解决方案......在网上寻找一些例子,我注意到有很多人有这个问题。我尝试(失败)使用 page.on("response") 事件来检索原始响应内容,根据以下代码段:
const bucket = [];
await page.on("response", async response => {
const url = response.url();
if (
url ===
"https://the.earth.li/~sgtatham/putty/0.71/w32/putty-0.71-installer.msi"
) {
try {
if (response.status() === 200) {
bucket.push(await response.buffer());
console.log(bucket);
// I got the following: 'Protocol error (Network.getResponseBody): No resource with given identifier found' }
}
} catch (err) {
console.error(err, "ERROR");
}
}
});
Run Code Online (Sandbox Code Playgroud)
使用上面这样的代码,我打算检测下载对话框的事件,然后以某种方式能够接收二进制内容。
我不确定这是否是正确的方法。我注意到有些人使用基于读取文件的解决方案,换句话说,下载完成后,他们从磁盘读取存储的文件。在https://github.com/GoogleChrome/puppeteer/issues/299 上也有类似的讨论。
我的问题是:有没有办法(使用 puppeteer)来拦截下载流,而不必事先将文件保存到磁盘?
非常感谢。
我想在我的 LinkedIn 文章中嵌入一段代码,如下所示:
该图像来自 Gitlab snippets ( https://gitlab.com/snippets/1841785 )。有什么方法可以在 LinkedIn 文章中呈现其内容吗?我在 LinkedIn feed 上看到了这篇文章,我很好奇如何做到这一点。
我注意到 Gitlab 提供了两种获取代码片段的方法:嵌入或共享内容。我应该如何使用?
谢谢。