File size: 3,375 Bytes
72a036c
 
 
f564b1b
 
72a036c
 
 
 
fa728fc
 
 
72a036c
 
 
 
 
 
 
 
 
 
 
fa728fc
 
 
72a036c
 
 
fa728fc
 
 
72a036c
 
 
bec2194
72a036c
 
 
f564b1b
 
 
 
 
 
72a036c
 
 
f564b1b
 
 
 
 
 
72a036c
f564b1b
72a036c
 
 
 
 
 
 
81c46e0
 
 
 
 
 
 
72a036c
 
f564b1b
72a036c
 
 
 
 
f564b1b
72a036c
 
 
fa728fc
18210ff
 
fa728fc
 
 
 
 
 
72a036c
18210ff
72a036c
 
 
 
 
18210ff
72a036c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const express = require("express");
const { chromium } = require("playwright-core");
const cheerio = require("cheerio");
const prettify = require("express-prettify");
const prettyjson = require("prettyjson");

const app = express();
const PORT = 7860;

// Use prettify middleware for JSON responses
app.use(prettify({ query: "pretty" }));

async function scrapeMatches() {
    const browser = await chromium.launch({
        headless: true,
        executablePath: "/usr/bin/chromium",
        args: ["--no-sandbox", "--disable-setuid-sandbox"]
    });

    const page = await browser.newPage();

    // Set headers to bypass bot detection
    await page.setExtraHTTPHeaders({
        "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",
        "Accept-Language": "en-US,en;q=0.9",
        "Referer": "https://www.google.com/"
    });

    // Block unnecessary requests (images, CSS, etc.)
    await page.route("**/*", (route) => {
        return ["image", "stylesheet", "font", "media"].includes(route.request().resourceType())
            ? route.abort()
            : route.continue();
    });

    // Navigate to main draw predictions page
    const baseURL = "https://www.windrawwin.com/predictions/today/all-games/large-stakes/draws/";
    await page.goto(baseURL, { waitUntil: "domcontentloaded", timeout: 60000 });

    // Get all league URLs
    const leagueLinks = await page.evaluate(() => {
        return Array.from(document.querySelectorAll("select#predregion option"))
            .map(option => option.value)
            .filter(link => link.includes("/predictions/today/"));
    });

    let allMatches = [];

    for (let link of leagueLinks) {
        await page.goto(link, { waitUntil: "domcontentloaded", timeout: 60000 });

        // Use evaluate to get full HTML for parsing
        const html = await page.evaluate(() => document.documentElement.outerHTML);
        const $ = cheerio.load(html);

        $(".wttr").each((_, element) => {
            const homeTeam = $(element).find(".wtteam .wtmoblnk").eq(0).text().trim();
            const awayTeam = $(element).find(".wtteam .wtmoblnk").eq(1).text().trim();
            const stake = $(element).find(".wttd.wtstk").text().trim();
            const prediction = $(element).find(".wttd.wtprd").text().trim();
            const score = $(element).find(".predscore").text().trim();

            if (homeTeam && awayTeam) {
                allMatches.push({
                    homeTeam,
                    awayTeam,
                    stake,
                    prediction,
                    score
                });
            }
        });
    }

    await browser.close();
    return allMatches;
}

// Express API route
app.get("/draw", async (req, res) => {
    try {
        const matches = await scrapeMatches();

        // Beautify response (Console Output)
        console.log("\nFetched Matches:");
        console.log(prettyjson.render(matches));

        res.json({
            success: true,
            data: matches
        });
    } catch (error) {
        console.error("Error fetching matches:", error);
        res.status(500).json({ success: false, message: "Failed to fetch data" });
    }
});

app.listen(PORT, () => {
    console.log(`\nServer running at http://localhost:${PORT}/draw\n`);
});