-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetch-sofascore.js
More file actions
38 lines (30 loc) · 1.13 KB
/
fetch-sofascore.js
File metadata and controls
38 lines (30 loc) · 1.13 KB
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
const puppeteer = require('puppeteer');
const fs = require('fs');
(async () => {
const browser = await puppeteer.launch({
headless: 'new',
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64)');
try {
for (let i = 0; i < 3; i++) {
const date = new Date();
date.setDate(date.getDate() + i);
const formattedDate = date.toLocaleDateString('en-CA', {
timeZone: 'Europe/London'
});
const url = `https://www.sofascore.com/api/v1/sport/football/scheduled-events/${formattedDate}`;
const outputFile = `scheduled-events${i === 0 ? '' : i + 1}.json`;
console.log(`📅 Fetching: ${formattedDate} -> ${outputFile}`);
const response = await page.goto(url, { waitUntil: 'networkidle0' });
const json = await response.json();
fs.writeFileSync(outputFile, JSON.stringify(json, null, 2));
}
console.log('✅ All files saved successfully!');
} catch (err) {
console.error('❌ Fetch failed:', err);
} finally {
await browser.close();
}
})();