Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Last active August 14, 2022 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloaj/1463169f0c7b4b04dc3f22b2cd2bca77 to your computer and use it in GitHub Desktop.
Save juanpabloaj/1463169f0c7b4b04dc3f22b2cd2bca77 to your computer and use it in GitHub Desktop.
download images with puppeteer
imgs
.DS_Store
node_modules
// 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