Skip to content

Instantly share code, notes, and snippets.

@hi-ogawa
Last active May 20, 2021 04:55
Show Gist options
  • Save hi-ogawa/8bdd97b3a8a0d3527d74d0354176612d to your computer and use it in GitHub Desktop.
Save hi-ogawa/8bdd97b3a8a0d3527d74d0354176612d to your computer and use it in GitHub Desktop.
Chess.com Drills Download

Usage

$ npm install jsdom argparse

$ node main.js https://www.chess.com/drills/endgame-fundamentals --format pgn
:: Downloading https://www.chess.com/drills/endgame-fundamentals?page=1
:: Downloading https://www.chess.com/drills/endgame-fundamentals?page=2
:: Downloading https://www.chess.com/drills/endgame-fundamentals?page=3
:: Downloading https://www.chess.com/drills/endgame-fundamentals?page=4
[Event "https://www.chess.com/drills/endgame-fundamentals (1)"]
[FEN "4k3/8/4K3/8/8/8/4P3/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (2)"]
[FEN "4k3/8/8/8/8/8/4P3/4K3 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (3)"]
[FEN "8/6kP/6P1/6K1/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (4)"]
[FEN "8/8/8/8/8/8/1k5P/6K1 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (5)"]
[FEN "8/8/1k6/8/P1P5/8/8/7K w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (6)"]
[FEN "8/8/p6k/8/P5PK/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (7)"]
[FEN "8/7p/8/8/1pk5/8/2K4P/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (8)"]
[FEN "8/8/1k1p4/3P1K2/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (9)"]
[FEN "5k2/8/5P1p/4K2P/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (10)"]
[FEN "5k2/p4ppp/8/8/8/8/PP3PPP/6K1 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (11)"]
[FEN "8/5pk1/6p1/8/2K2PP1/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (12)"]
[FEN "3k4/2p5/ppK5/8/8/8/PPP5/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (13)"]
[FEN "8/2k5/1p6/1P1K4/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (14)"]
[FEN "8/8/4k3/5p2/3K1Pp1/6P1/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (15)"]
[FEN "8/1p6/8/8/8/8/1P6/K6k w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (16)"]
[FEN "8/1p6/1P6/8/7K/8/8/1k6 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (17)"]
[FEN "6k1/7p/8/6K1/6P1/8/7P/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (18)"]
[FEN "8/2p5/8/kP6/2P5/8/8/K7 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (19)"]
[FEN "8/8/4k1p1/6Pp/8/5K2/8/8 w - - 2 2"]

[Event "https://www.chess.com/drills/endgame-fundamentals (20)"]
[FEN "8/4k3/3p4/3P4/2P5/8/8/5K2 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (21)"]
[FEN "8/6k1/6p1/6K1/5P1P/8/8/8 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (22)"]
[FEN "8/8/8/1p1p4/8/2P5/1K6/4k3 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (23)"]
[FEN "8/4k3/8/1p5p/1P5P/5K2/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (24)"]
[FEN "8/8/8/2p1k3/8/8/8/4K3 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (25)"]
[FEN "8/1p1k4/1P6/2PK4/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (26)"]
[FEN "1r4k1/ppp2pp1/7p/8/8/1NP2B1P/PP3PP1/5K2 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (27)"]
[FEN "8/8/8/3k4/8/8/1R3K2/6R1 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (28)"]
[FEN "2k5/5ppp/8/4p3/4P3/8/P4PPP/2K5 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (29)"]
[FEN "8/8/4k3/8/8/8/8/KQ6 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (30)"]
[FEN "K7/8/5P1k/p7/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (31)"]
[FEN "8/7n/6KP/8/8/8/8/k7 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (32)"]
[FEN "4K3/3P4/4k3/8/8/7r/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (33)"]
[FEN "8/8/8/2PK4/4N3/8/7b/7k w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (34)"]
[FEN "8/3PKnk1/8/8/8/8/8/7N w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (35)"]
[FEN "K2n4/8/P7/8/2k5/8/2N5/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (36)"]
[FEN "1k6/3K4/2P5/1n1N4/8/8/8/8 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (37)"]
[FEN "8/8/5nk1/8/5K2/4N1P1/7P/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (38)"]
[FEN "8/8/8/4k3/8/1r6/3BK3/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (39)"]
[FEN "8/8/8/8/5nk1/4B3/2BK4/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (40)"]
[FEN "8/8/3k4/p2b4/8/4K3/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (41)"]
[FEN "8/8/8/5KB1/p7/P4k2/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (42)"]
[FEN "2KB4/1P6/2k5/8/8/8/7b/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (43)"]
[FEN "2b2B2/8/p7/4k2p/8/8/8/4K3 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (44)"]
[FEN "8/2k1b3/2P5/3K1P1B/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (45)"]
[FEN "4n2B/3K4/2P5/2k5/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (46)"]
[FEN "5k2/8/6K1/8/8/R7/7b/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (47)"]
[FEN "6k1/8/3n2K1/8/5R2/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (48)"]
[FEN "3k4/4r3/3K4/3B4/8/8/8/5R2 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (49)"]
[FEN "4r3/2R5/8/2K5/2B1k3/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (50)"]
[FEN "4R3/2r5/8/2k5/2b1K3/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (51)"]
[FEN "8/8/5k2/2R3p1/3K4/8/6P1/1b6 w - - 9 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (52)"]
[FEN "k6r/6R1/2KN4/8/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (53)"]
[FEN "1k6/8/1K6/1N6/8/8/2r5/3R4 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (54)"]
[FEN "8/5n2/8/2r1k3/8/4K3/8/1R6 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (55)"]
[FEN "1r4k1/ppp2pp1/7p/8/8/1NP2B1P/PP3PP1/5K2 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (56)"]
[FEN "8/8/8/3k4/8/8/1R3K2/6R1 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (57)"]
[FEN "2k5/5ppp/8/4p3/4P3/8/P4PPP/2K5 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (58)"]
[FEN "8/8/4k3/8/8/8/8/KQ6 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (59)"]
[FEN "3r4/1R6/8/8/1n6/1k6/8/1K6 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (60)"]
[FEN "3K4/8/8/5p2/4k3/8/8/R7 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (61)"]
[FEN "8/2k5/R7/K7/5p2/6p1/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (62)"]
[FEN "r7/8/6kP/6P1/5PK1/8/8/8 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (63)"]
[FEN "1K1k4/1P6/8/8/8/8/r7/2R5 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (64)"]
[FEN "1r6/8/5k2/8/1P6/1K6/8/3R4 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (65)"]
[FEN "1R6/7k/1P6/8/8/6K1/8/1r6 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (66)"]
[FEN "1r6/8/8/8/1P1k4/1K6/8/2R5 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (67)"]
[FEN "1r6/8/8/8/4pk2/8/R3K3/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (68)"]
[FEN "5k2/R7/6K1/5P2/8/8/8/1r6 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (69)"]
[FEN "K7/P4k2/8/8/8/8/4R3/1r6 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (70)"]
[FEN "R7/P5pk/8/8/8/7P/5PK1/r7 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (71)"]
[FEN "7R/8/8/2k5/8/7p/1K6/7r w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (72)"]
[FEN "4r3/8/8/7k/4P3/4K3/8/6R1 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (73)"]
[FEN "3r4/8/8/6k1/3P4/3K4/8/5R2 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (74)"]
[FEN "1r6/8/8/4k3/1P6/1K6/3R4/8 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (75)"]
[FEN "8/8/8/R4p2/1r2k3/4p1P1/4K3/8 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (76)"]
[FEN "8/6k1/R7/1r5P/5PK1/8/8/8 b - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (77)"]
[FEN "8/8/8/8/3k4/1p6/1Pb5/K1Q5 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (78)"]
[FEN "k7/1r6/2K5/3Q4/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (79)"]
[FEN "4k3/1Q6/5r2/3K4/8/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (80)"]
[FEN "8/8/8/5r2/5k2/8/8/6KQ w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (81)"]
[FEN "8/1k6/1p6/r7/8/3K4/2Q5/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (82)"]
[FEN "K6Q/8/8/8/8/8/3pk3/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (83)"]
[FEN "8/8/1KP5/8/6k1/8/8/5q2 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (84)"]
[FEN "1r4k1/ppp2pp1/7p/8/8/1NP2B1P/PP3PP1/5K2 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (85)"]
[FEN "8/8/8/3k4/8/8/1R3K2/6R1 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (86)"]
[FEN "2k5/5ppp/8/4p3/4P3/8/P4PPP/2K5 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (87)"]
[FEN "8/8/4k3/8/8/8/8/KQ6 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (88)"]
[FEN "1Q6/8/6q1/3k4/8/3p4/8/3K4 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (89)"]
[FEN "8/Q2K4/3P4/8/5q2/8/7k/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (90)"]
[FEN "6Q1/q7/3k4/8/5P2/5K2/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (91)"]
[FEN "8/6PK/8/5Q2/1k6/8/7q/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (92)"]
[FEN "8/8/1k6/1p5Q/4K3/8/5q2/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (93)"]
[FEN "8/8/3k4/3p4/3K4/8/8/8 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (94)"]
[FEN "1r4k1/ppp2pp1/7p/8/8/1NP2B1P/PP3PP1/5K2 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (95)"]
[FEN "8/8/8/3k4/8/8/1R3K2/6R1 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (96)"]
[FEN "2k5/5ppp/8/4p3/4P3/8/P4PPP/2K5 w - - 0 1"]

[Event "https://www.chess.com/drills/endgame-fundamentals (97)"]
[FEN "8/8/4k3/8/8/8/8/KQ6 w - - 0 1"]
const { JSDOM } = require("jsdom");
const { ArgumentParser } = require('argparse');
const getDocument = async (url) => {
const { window } = await JSDOM.fromURL(url);
return window.document;
}
const getDrills = async (url) => {
const results = []
for (let page = 1; ; page++) {
const pageUrl = `${url}?page=${page}`;
console.error(`:: Downloading ${pageUrl}`)
const document = await getDocument(pageUrl);
const nodes = document.querySelectorAll('.drills-board-preview > div');
for (const node of nodes) {
results.push(node.getAttribute('fen'));
}
const link = document.querySelector('link[rel="next"]');
if (!link) {
break;
}
}
return results;
};
const main = async ({ url, format }) => {
const drills = await getDrills(url);
for (let i = 0; i < drills.length; i++) {
const fen = drills[i];
console.log((format === 'fen') ? fen : `[Event "${url} (${i + 1})"]\n[FEN "${fen}"]\n`);
}
}
const mainCli = () => {
const parser = new ArgumentParser();
parser.add_argument('url');
parser.add_argument('--format', { default: 'fen', choices: ['fen', 'pgn'] });
main(parser.parse_args());
}
mainCli();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment