Skip to content

Instantly share code, notes, and snippets.

@Schniz
Created October 16, 2020 09:41
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 Schniz/e41ae208f17eebe869bc46d1eaa3c84b to your computer and use it in GitHub Desktop.
Save Schniz/e41ae208f17eebe869bc46d1eaa3c84b to your computer and use it in GitHub Desktop.
Download Shvetz stickers
const puppeteer = require("puppeteer");
const { default: fetch } = require("node-fetch");
const path = require("path");
const fs = require("fs");
const FILES = path.join(__dirname, "shvetz");
async function main() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
"https://getstickerpack.com/stickers/mspht-swwz-pyylwt"
);
const sources = await page.$$eval(".sticker-pack-cols img", (images) => {
return images.map((x) => x.src);
});
const urls = sources
.map((s) => new URL(s))
.map((url) => {
url.search = "";
return url;
});
await Promise.all(
urls.map(async (url) => {
const response = await fetch(url);
if (response.status !== 200) {
console.error(`${url} not accessible: ${response.status}`);
return;
}
const filename = path.basename(url.pathname);
const stream = fs.createWriteStream(path.join(FILES, filename));
await new Promise((res) => response.body.pipe(stream).once("end", res));
})
);
await page.close();
await browser.close();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment