Update server.js
Browse files
server.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
const express = require("express");
|
2 |
const { chromium } = require("playwright-core");
|
3 |
const cheerio = require("cheerio");
|
4 |
-
const prettify = require("express-prettify");
|
5 |
-
const prettyjson = require("prettyjson");
|
6 |
|
7 |
const app = express();
|
8 |
const PORT = 7860;
|
@@ -37,16 +37,23 @@ async function scrapeMatches() {
|
|
37 |
const baseURL = "https://www.windrawwin.com/predictions/today/all-games/large-stakes/draws/";
|
38 |
await page.goto(baseURL, { waitUntil: "domcontentloaded", timeout: 60000 });
|
39 |
|
40 |
-
|
41 |
-
const
|
|
|
|
|
|
|
|
|
42 |
|
43 |
let allMatches = [];
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
|
49 |
-
$(
|
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();
|
@@ -55,7 +62,6 @@ async function scrapeMatches() {
|
|
55 |
|
56 |
if (homeTeam && awayTeam) {
|
57 |
allMatches.push({
|
58 |
-
competition: competitionName,
|
59 |
homeTeam,
|
60 |
awayTeam,
|
61 |
stake,
|
@@ -64,13 +70,13 @@ async function scrapeMatches() {
|
|
64 |
});
|
65 |
}
|
66 |
});
|
67 |
-
}
|
68 |
|
69 |
await browser.close();
|
70 |
return allMatches;
|
71 |
}
|
72 |
|
73 |
-
// Express API route
|
74 |
app.get("/draw", async (req, res) => {
|
75 |
try {
|
76 |
const matches = await scrapeMatches();
|
|
|
1 |
const express = require("express");
|
2 |
const { chromium } = require("playwright-core");
|
3 |
const cheerio = require("cheerio");
|
4 |
+
const prettify = require("express-prettify");
|
5 |
+
const prettyjson = require("prettyjson");
|
6 |
|
7 |
const app = express();
|
8 |
const PORT = 7860;
|
|
|
37 |
const baseURL = "https://www.windrawwin.com/predictions/today/all-games/large-stakes/draws/";
|
38 |
await page.goto(baseURL, { waitUntil: "domcontentloaded", timeout: 60000 });
|
39 |
|
40 |
+
// Get all league URLs
|
41 |
+
const leagueLinks = await page.evaluate(() => {
|
42 |
+
return Array.from(document.querySelectorAll("select#predregion option"))
|
43 |
+
.map(option => option.value)
|
44 |
+
.filter(link => link.includes("/predictions/today/"));
|
45 |
+
});
|
46 |
|
47 |
let allMatches = [];
|
48 |
|
49 |
+
for (let link of leagueLinks) {
|
50 |
+
await page.goto(link, { waitUntil: "domcontentloaded", timeout: 60000 });
|
51 |
+
|
52 |
+
// Use evaluate to get full HTML for parsing
|
53 |
+
const html = await page.evaluate(() => document.documentElement.outerHTML);
|
54 |
+
const $ = cheerio.load(html);
|
55 |
|
56 |
+
$(".wttr").each((_, element) => {
|
57 |
const homeTeam = $(element).find(".wtteam .wtmoblnk").eq(0).text().trim();
|
58 |
const awayTeam = $(element).find(".wtteam .wtmoblnk").eq(1).text().trim();
|
59 |
const stake = $(element).find(".wttd.wtstk").text().trim();
|
|
|
62 |
|
63 |
if (homeTeam && awayTeam) {
|
64 |
allMatches.push({
|
|
|
65 |
homeTeam,
|
66 |
awayTeam,
|
67 |
stake,
|
|
|
70 |
});
|
71 |
}
|
72 |
});
|
73 |
+
}
|
74 |
|
75 |
await browser.close();
|
76 |
return allMatches;
|
77 |
}
|
78 |
|
79 |
+
// Express API route
|
80 |
app.get("/draw", async (req, res) => {
|
81 |
try {
|
82 |
const matches = await scrapeMatches();
|