Last active
August 14, 2022 14:53
-
-
Save juanpabloaj/1463169f0c7b4b04dc3f22b2cd2bca77 to your computer and use it in GitHub Desktop.
download images with puppeteer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imgs | |
.DS_Store | |
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm i puppeteer | |
// use puppeteer 14.3.0 | |
const puppeteer = require("puppeteer"); | |
const path = require("path"); | |
const downloadPath = path.resolve("./imgs"); | |
const args = process.argv.slice(2); | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.setDefaultNavigationTimeout(0); | |
page | |
.on("console", async (msg) => { | |
const msgType = msg.type(); | |
if (msgType === "log" || msgType === "debug") { | |
console.log(new Date(), msgType, msg.text()); | |
} | |
if (msg.text().includes("total time")) { | |
await page.waitForTimeout(3000); | |
await browser.close(); | |
} | |
}) | |
.on("pageerror", ({ message }) => console.error(new Date(), message)); | |
let fxhash = args[0] || ""; | |
await page.goto("http://localhost:8080?fxhash=" + fxhash); | |
await page._client.send("Page.setDownloadBehavior", { | |
behavior: "allow", | |
downloadPath: downloadPath, | |
}); | |
//await page.waitForTimeout(30000); | |
//await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment