提问人:kajl16 提问时间:11/17/2023 更新时间:11/17/2023 访问量:26
有没有办法在 aws lambda 上使用 puppeteer 下载文件?
Is there a way to download a file using puppeteer on aws lambda?
问:
我刚刚开始学习 puppeteer,我想问一下有没有办法使用 puppeteer 和 aws lambda 下载文件?我的目标是将下载的文件发送到 s3 存储桶。我尝试在互联网上搜索,但教程至少有 2 年的历史,所以我会掷骰子并在这里提问。我现在知道的是,我至少需要傀儡核心和节点模块中的无头铬,如 @sparticuz/铬?但据我所知,因为我看到的教程并不是那么详细。
下面的代码在我的本地运行良好,所以我希望有一些指针或人们将我指向正确的位置,以使此代码在 aws lambda 上运行。提前致谢!
const puppeteer = require('puppeteer');
const fs = require('fs');
const https = require('https');
async function run() {
let browser;
const isHeadless = true;
try {
browser = await puppeteer.launch({ headless: isHeadless });
const page = await browser.newPage();
page.setDefaultNavigationTimeout(2 * 60 * 1000);
if (isHeadless) {
const client = await page.target().createCDPSession();
await client.send('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: 'C:\\Users\\user\\Downloads\\'
});
}
await page.goto('https://app.website.com/login');
await page.type('#email', '[email protected]');
await page.type('#password', 'password')
await page.click('[data-cy="submit"]');
await page.waitForNavigation();
const el = await page.$x('//*[@id="download_button"]/div/a[1]');
if (el.length > 0) {
await el[0].click();
} else {
console.log('element not found');
}
console.log('download complete.');
} catch (e) {
console.error('run failed', e);
} finally {
if (browser) {
await browser.close();
}
}
}
run();
tldr:我想使用 puppeteer 将从 lambda 函数下载的文件发送到 s3
答: 暂无答案
评论