-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (37 loc) · 1.47 KB
/
index.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
40
41
42
43
44
import initializeBrowser from './src/browser';
import navigateToMatchesPage from './src/pageNavigation';
import extractMatchData from './src/matchExtractor';
import extractAceStreamLinks from './src/acestreamExtractor';
import writeDataToFile from './src/dataWriter';
const main = async () => {
const url = 'https://duckhub.net';
const loaderSelector = '#loader';
const buttonClickSelector = 'body > div.menu > div > label:nth-child(3)';
const cardSelectors = {
card: 'div.par_dark-partidos',
title: 'h3.evento-titulo',
sport: 'p:nth-child(2)',
competition: 'p:nth-child(3)',
date: 'p:nth-child(4)',
button: 'button.par_button'
};
try {
const { browser, page } = await initializeBrowser();
await navigateToMatchesPage(page, url, loaderSelector, buttonClickSelector);
const matches = [];
const elements = await page.$$(cardSelectors.card);
for (const element of elements) {
const match = await extractMatchData(element, cardSelectors);
const channels = await extractAceStreamLinks(element, cardSelectors.button, page, loaderSelector);
match.channels = channels;
matches.push(match);
// console.log({ matches })
}
// Escribe los datos en data.json
writeDataToFile(matches);
await browser.close();
} catch (error) {
console.error("Error in the main process: ", error);
}
};
main();