Created
February 6, 2023 18:52
-
-
Save skinnyfads/7821f7c60e106f3d3c3ab6567e408be3 to your computer and use it in GitHub Desktop.
Get all the json files from https://jlptstudy.net/
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
import fs from "node:fs"; | |
import axios from "axios"; | |
const baseUrl = "https://jlptstudy.net"; | |
const pattern = /<a\s+(?:[^>]*?\s+)?href=(["'])(.*?)\1/g; | |
(async () => { | |
// stop at 1 cause jlptstudy.net doesn't have the kanji n1 | |
for (let nNumber = 5; nNumber > 1; nNumber--) { | |
const dirname = "n" + nNumber; | |
fs.mkdirSync(dirname); | |
const indexUrl = baseUrl + `/N${nNumber}/lists/`; | |
const response = await axios.get(indexUrl); | |
const matchedHref = response.data.matchAll(pattern); | |
for (const href of matchedHref) { | |
const filename = href[2]; | |
if (filename.startsWith("n" + nNumber) && filename.endsWith("json")) { | |
const response = await axios.get(indexUrl + filename); | |
fs.writeFileSync(`./${dirname}/${filename}`, JSON.stringify(response.data)); | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment