Rename index.js to server.js
Browse files
index.js
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
const puppeteer = require('puppeteer-extra');
|
2 |
-
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
3 |
-
const cheerio = require('cheerio');
|
4 |
-
|
5 |
-
puppeteer.use(StealthPlugin());
|
6 |
-
|
7 |
-
(async () => {
|
8 |
-
const browser = await puppeteer.launch({
|
9 |
-
headless: true,
|
10 |
-
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
11 |
-
});
|
12 |
-
|
13 |
-
const page = await browser.newPage();
|
14 |
-
|
15 |
-
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
|
16 |
-
await page.setExtraHTTPHeaders({
|
17 |
-
'Accept-Language': 'en-US,en;q=0.9',
|
18 |
-
'Referer': 'https://www.google.com/'
|
19 |
-
});
|
20 |
-
|
21 |
-
await page.setRequestInterception(true);
|
22 |
-
page.on('request', (req) => {
|
23 |
-
if (['image', 'stylesheet', 'font'].includes(req.resourceType())) {
|
24 |
-
req.abort();
|
25 |
-
} else {
|
26 |
-
req.continue();
|
27 |
-
}
|
28 |
-
});
|
29 |
-
|
30 |
-
await page.goto('https://www.windrawwin.com/predictions/today/all-games/large-stakes/draws/', {
|
31 |
-
waitUntil: 'domcontentloaded',
|
32 |
-
timeout: 60000
|
33 |
-
});
|
34 |
-
|
35 |
-
const html = await page.evaluate(() => document.body.innerHTML);
|
36 |
-
const $ = cheerio.load(html);
|
37 |
-
let matches = [];
|
38 |
-
|
39 |
-
$('.wttr').each((_, element) => {
|
40 |
-
const homeTeam = $(element).find('.wtteam .wtmoblnk').eq(0).text().trim();
|
41 |
-
const awayTeam = $(element).find('.wtteam .wtmoblnk').eq(1).text().trim();
|
42 |
-
const stake = $(element).find('.wttd.wtstk').text().trim();
|
43 |
-
const prediction = $(element).find('.wttd.wtprd').text().trim();
|
44 |
-
const score = $(element).find('.predscore').text().trim();
|
45 |
-
|
46 |
-
if (homeTeam && awayTeam) {
|
47 |
-
matches.push({ homeTeam, awayTeam, stake, prediction, score });
|
48 |
-
}
|
49 |
-
});
|
50 |
-
|
51 |
-
console.log(matches);
|
52 |
-
await browser.close();
|
53 |
-
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.js
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const { chromium } = require("playwright-core");
|
3 |
+
const cheerio = require("cheerio");
|
4 |
+
|
5 |
+
const app = express();
|
6 |
+
const PORT = 7860;
|
7 |
+
|
8 |
+
async function scrapeMatches() {
|
9 |
+
const browser = await chromium.launch({
|
10 |
+
headless: true,
|
11 |
+
executablePath: "/usr/bin/chromium",
|
12 |
+
args: ["--no-sandbox", "--disable-setuid-sandbox"]
|
13 |
+
});
|
14 |
+
|
15 |
+
const page = await browser.newPage();
|
16 |
+
|
17 |
+
// Set headers to bypass bot detection
|
18 |
+
await page.setExtraHTTPHeaders({
|
19 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
20 |
+
'Accept-Language': 'en-US,en;q=0.9',
|
21 |
+
'Referer': 'https://www.google.com/'
|
22 |
+
});
|
23 |
+
|
24 |
+
// Block unnecessary requests (images, CSS, etc.)
|
25 |
+
await page.route('**/*', (route) => {
|
26 |
+
return ['image', 'stylesheet', 'font', 'media'].includes(route.request().resourceType())
|
27 |
+
? route.abort()
|
28 |
+
: route.continue();
|
29 |
+
});
|
30 |
+
|
31 |
+
// Navigate to the predictions page
|
32 |
+
const baseURL = "https://www.windrawwin.com/predictions/today/all-games/large-stakes/draws/";
|
33 |
+
await page.goto(baseURL, { waitUntil: "domcontentloaded", timeout: 60000 });
|
34 |
+
|
35 |
+
// Extract all available league URLs
|
36 |
+
const leagueLinks = await page.evaluate(() => {
|
37 |
+
return Array.from(document.querySelectorAll("select#predregion option"))
|
38 |
+
.map(option => option.value)
|
39 |
+
.filter(link => link.includes("/predictions/today/"));
|
40 |
+
});
|
41 |
+
|
42 |
+
let allMatches = [];
|
43 |
+
|
44 |
+
for (let link of leagueLinks) {
|
45 |
+
await page.goto(link, { waitUntil: "domcontentloaded", timeout: 60000 });
|
46 |
+
const html = await page.content();
|
47 |
+
const $ = cheerio.load(html);
|
48 |
+
|
49 |
+
$(".wttr").each((_, element) => {
|
50 |
+
const homeTeam = $(element).find(".wtteam .wtmoblnk").eq(0).text().trim();
|
51 |
+
const awayTeam = $(element).find(".wtteam .wtmoblnk").eq(1).text().trim();
|
52 |
+
const stake = $(element).find(".wttd.wtstk").text().trim();
|
53 |
+
const prediction = $(element).find(".wttd.wtprd").text().trim();
|
54 |
+
const score = $(element).find(".predscore").text().trim();
|
55 |
+
|
56 |
+
if (homeTeam && awayTeam) {
|
57 |
+
allMatches.push({ homeTeam, awayTeam, stake, prediction, score });
|
58 |
+
}
|
59 |
+
});
|
60 |
+
}
|
61 |
+
|
62 |
+
await browser.close();
|
63 |
+
return allMatches;
|
64 |
+
}
|
65 |
+
|
66 |
+
// Express API route
|
67 |
+
app.get("/draw", async (req, res) => {
|
68 |
+
try {
|
69 |
+
const matches = await scrapeMatches();
|
70 |
+
res.json({ success: true, data: matches });
|
71 |
+
} catch (error) {
|
72 |
+
console.error("Error:", error);
|
73 |
+
res.status(500).json({ success: false, message: "Failed to fetch data" });
|
74 |
+
}
|
75 |
+
});
|
76 |
+
|
77 |
+
app.listen(PORT, () => {
|
78 |
+
console.log(`Server running at http://localhost:${PORT}/draw`);
|
79 |
+
});
|