-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextractor.ts
32 lines (31 loc) · 920 Bytes
/
extractor.ts
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
import { gotScraping } from 'got-scraping';
import cheerio from 'cheerio';
import cliProgress from 'cli-progress';
export async function extractor(link: string | URL, words: Array<string>) {
const bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
const total = words.length;
console.log('Progress');
bar1.start(total, 0);
const synonyms = await Promise.allSettled(
words.map(async (word) => {
try {
const response = await gotScraping(`${link}/${word}`);
const html = response.body;
const $ = cheerio.load(html);
const synonyms = $('#meanings > div.css-ixatld.e15rdun50 > ul > li')
.map(function () {
return $(this).find('a').text().trim();
})
.get();
// console.log(synonyms);
bar1.increment();
return { word, synonyms };
} catch (error) {
console.log(error);
return { word };
}
})
);
bar1.stop();
return synonyms;
}