-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.js
39 lines (33 loc) · 954 Bytes
/
scraper.js
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
import Xray from 'x-ray';
import fs from 'fs';
const file = fs.createWriteStream('prefixes.txt');
const x = Xray();
const getAllLinks = async () => x('http://airfoiltools.com/search/airfoils',
'.listtable', ['td']).then((link) => {
const tempLinks = [];
for (let i = 0; i < link.length; i += 1) {
tempLinks.push(link[i]);
}
return tempLinks;
});
const getAllLinksWaited = async () => {
const untrimmedLinks = await getAllLinks();
const trimmedLinks = untrimmedLinks.map(((link) => {
const stringLink = `${link}`;
const splitLinks = stringLink.split('-');
if (splitLinks.length >= 2) {
const prefix = splitLinks.splice(0, 2);
return `${prefix[0]}-${prefix[1]}`.trim('');
}
return '';
}));
console.log(trimmedLinks);
trimmedLinks.forEach((trimmed) => {
if (trimmed) {
file.write(`${trimmed}\n`);
}
});
file.end();
};
getAllLinksWaited();
console.log('Wrote to prefixes.txt');