~shreyasminocha/leetcode-problem-scrape

bb762c9ef39da55b7cd8662929df5fcb48742732 — Shreyas Minocha 2 years ago ada830e
Write problem data to files
1 files changed, 9 insertions(+), 2 deletions(-)

M index.js
M index.js => index.js +9 -2
@@ 1,12 1,18 @@
import got from 'got';
import * as fs from 'fs/promises';
import path from 'path';

const dumpPath = process.argv[2];

let response = await got('https://leetcode.com/api/problems/all/').json();
const problems = response.stat_status_pairs;

await fs.mkdir(path.join(dumpPath, 'problems'));

for (const problem of problems) {
	const slug = problem.stat.question__title_slug;

	const response = await got.post('https://leetcode.com/graphql', {
	response = await got.post('https://leetcode.com/graphql', {
		json: {
			operationName: "questionData",
			variables: { titleSlug: slug },


@@ 15,5 21,6 @@ for (const problem of problems) {
	}).json();

	const { question } = response.data;
	console.log(question.title);

	fs.writeFile(path.join(dumpPath, 'problems', `${slug}.json`), JSON.stringify(question));
}