Skip to content

Instantly share code, notes, and snippets.

@ppalone
Last active October 6, 2023 20:47
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 ppalone/cb72ed5bab9546e97f9fc623b88d5067 to your computer and use it in GitHub Desktop.
Save ppalone/cb72ed5bab9546e97f9fc623b88d5067 to your computer and use it in GitHub Desktop.
Node script to download Tokyo revengers manga
// Dependenices
const cheerio = require("cheerio");
const axios = require("axios").default;
const fs = require("fs/promises");
const fscore = require("fs");
const path = require("path");
// constants
const BASE_URL = "https://tokyorevengersmanga.com/";
const FOLDER_NAME = "manga";
(async () => {
try {
const res = await axios.get(BASE_URL)
const $ = cheerio.load(res.data)
const posts = $("li.su-post")
const t = []
posts.each((_, post) => {
t.push({
id: parseInt(post.attribs.id.split("-")[2], 10),
link: post.firstChild.attribs.href,
})
})
const s = t.sort((a, b) => a.id - b.id)
for (let i = 0; i < s.length; i++) {
const d = path.join(__dirname, FOLDER_NAME, `chapter-${i + 1}`)
await fs.mkdir(d, { recursive: true })
const res = await axios.get(s[i].link)
const $ = cheerio.load(res.data)
const images = $(".entry-content .separator > img")
const t = []
images.each((_, img) => {
t.push(img.attribs.src)
})
for (let j = 0; j < t.length; j++) {
const res = await axios({
method: "GET",
url: t[j],
responseType: "stream"
})
res.data.pipe(fscore.createWriteStream(path.join(d, `${j + 1}.jpg`)))
}
}
} catch (err) {
console.error(err)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment