Created
October 16, 2020 09:41
-
-
Save Schniz/e41ae208f17eebe869bc46d1eaa3c84b to your computer and use it in GitHub Desktop.
Download Shvetz stickers
This file contains 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
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