-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist2.js
More file actions
53 lines (36 loc) · 975 Bytes
/
list2.js
File metadata and controls
53 lines (36 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const puppeteer = require('puppeteer');
const path = require('path');
const fs = require('fs');
const wFile = require('./util/wFile');
const pgn = require('./pgn.json');
const list = pgn.list;
if (!fs.existsSync('pgn')) {
fs.mkdirSync('pgn');
}
async function fetchList() {
const browser = await puppeteer.launch({
headless: false,
});
let page;
const pages = await browser.pages();
if (pages[0]) {
page = pages[0]
} else {
page = await browser.newPage();
}
for (const item of list) {
const curFile = path.join(__dirname, 'pgn', `${item.date}-${item.id}.pgn`);
if (fs.existsSync(curFile)) {
continue;
}
const p = `https://www.chessgames.com/perl/nph-chesspgn?text=1&gid=${item.id}`;
await page.goto(p);
const text = await page.evaluate(() => {
return document.querySelector('html').innerText;
});
await wFile(curFile, text);
}
await browser.close();
};
fetchList();