|
const express = require("express"); |
|
const { chromium } = require("playwright-core"); |
|
const cheerio = require("cheerio"); |
|
const prettify = require("express-prettify"); |
|
const prettyjson = require("prettyjson"); |
|
const chalk = require("chalk"); |
|
|
|
const app = express(); |
|
const PORT = 7860; |
|
|
|
|
|
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(); |
|
|
|
|
|
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/" |
|
}); |
|
|
|
|
|
await page.route("**/*", (route) => { |
|
return ["image", "stylesheet", "font", "media"].includes(route.request().resourceType()) |
|
? route.abort() |
|
: route.continue(); |
|
}); |
|
|
|
|
|
const baseURL = "https://www.windrawwin.com/predictions/today/all-games/large-stakes/draws/"; |
|
await page.goto(baseURL, { waitUntil: "domcontentloaded", timeout: 60000 }); |
|
|
|
const html = await page.content(); |
|
const $ = cheerio.load(html); |
|
|
|
let allMatches = []; |
|
|
|
|
|
$(".wtcont").each((_, competitionElement) => { |
|
const competitionName = $(competitionElement).find(".ptleag").text().trim(); |
|
|
|
$(competitionElement).find(".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({ |
|
competition: competitionName, |
|
homeTeam, |
|
awayTeam, |
|
stake, |
|
prediction, |
|
score |
|
}); |
|
} |
|
}); |
|
}); |
|
|
|
await browser.close(); |
|
return allMatches; |
|
} |
|
|
|
|
|
app.get("/draw", async (req, res) => { |
|
try { |
|
const matches = await scrapeMatches(); |
|
|
|
|
|
console.log(chalk.green("\nFetched Matches:")); |
|
console.log(prettyjson.render(matches)); |
|
|
|
res.json({ |
|
success: true, |
|
data: matches |
|
}); |
|
} catch (error) { |
|
console.error(chalk.red("Error fetching matches:"), error); |
|
res.status(500).json({ success: false, message: "Failed to fetch data" }); |
|
} |
|
}); |
|
|
|
app.listen(PORT, () => { |
|
console.log(chalk.blue(`\nServer running at http://localhost:${PORT}/draw\n`)); |
|
}); |