Reaperxxxx commited on
Commit
fa728fc
·
verified ·
1 Parent(s): bec2194

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +32 -22
server.js CHANGED
@@ -1,10 +1,16 @@
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,
@@ -16,15 +22,15 @@ async function scrapeMatches() {
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
 
@@ -32,21 +38,16 @@ async function scrapeMatches() {
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
- // Get all 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();
@@ -55,6 +56,7 @@ async function scrapeMatches() {
55
 
56
  if (homeTeam && awayTeam) {
57
  allMatches.push({
 
58
  homeTeam,
59
  awayTeam,
60
  stake,
@@ -63,23 +65,31 @@ async function scrapeMatches() {
63
  });
64
  }
65
  });
66
- }
67
 
68
  await browser.close();
69
  return allMatches;
70
  }
71
 
72
- // Express API route
73
  app.get("/draw", async (req, res) => {
74
  try {
75
  const matches = await scrapeMatches();
76
- res.json({ success: true, data: matches });
 
 
 
 
 
 
 
 
77
  } catch (error) {
78
- console.error("Error:", error);
79
  res.status(500).json({ success: false, message: "Failed to fetch data" });
80
  }
81
  });
82
 
83
  app.listen(PORT, () => {
84
- console.log(`Server running at http://localhost:${PORT}/draw`);
85
  });
 
1
  const express = require("express");
2
  const { chromium } = require("playwright-core");
3
  const cheerio = require("cheerio");
4
+ const prettify = require("express-prettify"); // Auto-pretty JSON
5
+ const prettyjson = require("prettyjson"); // Human-readable formatting
6
+ const chalk = require("chalk"); // Colorful console output
7
 
8
  const app = express();
9
  const PORT = 7860;
10
 
11
+ // Use prettify middleware for JSON responses
12
+ app.use(prettify({ query: "pretty" }));
13
+
14
  async function scrapeMatches() {
15
  const browser = await chromium.launch({
16
  headless: true,
 
22
 
23
  // Set headers to bypass bot detection
24
  await page.setExtraHTTPHeaders({
25
+ "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",
26
+ "Accept-Language": "en-US,en;q=0.9",
27
+ "Referer": "https://www.google.com/"
28
  });
29
 
30
  // Block unnecessary requests (images, CSS, etc.)
31
+ await page.route("**/*", (route) => {
32
+ return ["image", "stylesheet", "font", "media"].includes(route.request().resourceType())
33
+ ? route.abort()
34
  : route.continue();
35
  });
36
 
 
38
  const baseURL = "https://www.windrawwin.com/predictions/today/all-games/large-stakes/draws/";
39
  await page.goto(baseURL, { waitUntil: "domcontentloaded", timeout: 60000 });
40
 
41
+ const html = await page.content();
42
+ const $ = cheerio.load(html);
 
 
 
 
43
 
44
  let allMatches = [];
45
 
46
+ // Extract matches from all competitions
47
+ $(".wtcont").each((_, competitionElement) => {
48
+ const competitionName = $(competitionElement).find(".ptleag").text().trim();
 
49
 
50
+ $(competitionElement).find(".wttr").each((_, element) => {
51
  const homeTeam = $(element).find(".wtteam .wtmoblnk").eq(0).text().trim();
52
  const awayTeam = $(element).find(".wtteam .wtmoblnk").eq(1).text().trim();
53
  const stake = $(element).find(".wttd.wtstk").text().trim();
 
56
 
57
  if (homeTeam && awayTeam) {
58
  allMatches.push({
59
+ competition: competitionName,
60
  homeTeam,
61
  awayTeam,
62
  stake,
 
65
  });
66
  }
67
  });
68
+ });
69
 
70
  await browser.close();
71
  return allMatches;
72
  }
73
 
74
+ // Express API route with beautified response
75
  app.get("/draw", async (req, res) => {
76
  try {
77
  const matches = await scrapeMatches();
78
+
79
+ // Beautify response
80
+ console.log(chalk.green("\nFetched Matches:"));
81
+ console.log(prettyjson.render(matches));
82
+
83
+ res.json({
84
+ success: true,
85
+ data: matches
86
+ });
87
  } catch (error) {
88
+ console.error(chalk.red("Error fetching matches:"), error);
89
  res.status(500).json({ success: false, message: "Failed to fetch data" });
90
  }
91
  });
92
 
93
  app.listen(PORT, () => {
94
+ console.log(chalk.blue(`\nServer running at http://localhost:${PORT}/draw\n`));
95
  });