-
Notifications
You must be signed in to change notification settings - Fork 1
/
capture.js
55 lines (45 loc) · 1.58 KB
/
capture.js
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
√const puppeteer = require("puppeteer-extra");
const launch = require("./launch");
const fs = require("fs");
const wait = (ms) => new Promise((res) => setTimeout(res, ms));
//get WsEndpoint
async function getWsEndpoint() {
let wsEndpoint = await launch();
return wsEndpoint;
}
(async () => {
const browser = await puppeteer.connect({
browserWSEndpoint: await getWsEndpoint(),
defaultViewport: null,
});
let page = await browser.newPage();
await page.goto("https://ar.1xbet.com/es/allgamesentrance/fishing");
const client = await page.target().createCDPSession();
await client.send("Network.enable");
client.on(
"Network.webSocketFrameReceived",
({ requestId, timestamp, response }) => {
let payloadString = response.payloadData.toString("utf8");
try {
if (payloadString.includes('"target":"OnFish"')) {
payloadString = payloadString.replace(/[^\x20-\x7E]/g, "");
const payload = JSON.parse(payloadString);
const { st, i, ft, cf, tcf, us, gs } = payload.arguments[0];
console.log(st, i, ft, cf, tcf, us, gs);
const csvData = `${st},${i},${ft},${cf},${tcf},${us},${gs}\n`;
fs.appendFile("data.csv", csvData, (err) => {
if (err) throw err;
});
}
} catch (error) {
console.error("Error processing WebSocket frame:", error);
}
}
);
while (true) {
await page.keyboard.press("Tab");
await wait(1000);
await page.keyboard.press("ArrowDown");
await wait(1000);
}
})();