Это мой первый опыт работы с NodeJS, и я хочу удалить содержимое страницы, основываясь на параметре, который я передал в URL.
const cheerio = require('cheerio');
const https = require('https');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Type station name ', (search) => {
for (let i = 0; i <= 4000; i++) {
(async (url) => {
const content = await getScript(url);
const $ = cheerio.load(content);
let stationName = $('div[class=here] span[class=txtbold]').text();
if(stationName.toUpperCase().includes(search.toUpperCase())) {
console.log(stationName + ": " + i);
}
})('https://cg06.tsi.cityway.fr/qrcode/?id=' + i);
}
rl.close();
});
const getScript = (url) => {
return new Promise((resolve, reject) => {
https.get(url, (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
resolve(data);
});
}).on("error", (err) => {
reject(err);
});
});
};
Проблема в том, что у меня 4000 итераций ивыполнение этого сценария занимает слишком много времени.
Как мне решить эту проблему, пожалуйста?
Заранее спасибо