-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
118 lines (98 loc) · 4.13 KB
/
index.ts
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { drawMaps, saveMapResult, style, workbook, worksheet } from "./excel";
import { drawGames } from "./maps";
const playwright = require('playwright');
const cheerio = require('cheerio')
let text = Array<any>();
// const fs = require('node:fs');
// fs.readFile('hltv.txt', 'utf8', (err, data) => {
// if (err) {
// console.error(err);
// return;
// }
// text = JSON.parse(data);
// console.log(text.length);
// });
// async function test(){
// const browser = await playwright.chromium.launch({headless: false});
// const page = await browser.newPage();
// for(let i = 520; i < 600; i++) {
// await page.goto(`https://egamersworld.com/counterstrike/matches/history/page/${i}`);
// let html = await page.content();
// let index = 0;
// // do {
// const searchStr = 'tournament_id';
// let indexes = [...html.matchAll(new RegExp(searchStr, 'gi'))].map(a => a.index);
// indexes = indexes.filter(x=>x !== indexes[indexes.length-1]);
// for (const index of indexes) {
// let newindex = html.indexOf(`"tournament_id\\":\\`, index);
// let tournament_id = html.slice(newindex + 19, newindex + 35);
// let slug_index = html.indexOf('"slug\\":\\"', index);
// let slug_id = html.slice(slug_index + 10, slug_index + 100);
// let url = 'https://egamersworld.com/counterstrike/match/' + tournament_id.slice(0, tournament_id.indexOf('\\')) + '/' + slug_id.slice(0, slug_id.indexOf(`\\"`));
// if(!text.includes(url)) {
// text.push(url);
// }
// }
// // let tournament_id = html.slice(newindex).slice(html.indexOf(`"tournament_id\\":\\`) + 19, html.indexOf(`"tournament_id\\":\\`) + 35);
// // console.log(indexes);
// // index = newindex;
// // } while(index < html.length);
// // let tournament_id = html.slice(html.indexOf(`"tournament_id\\":\\`) + 19, html.indexOf(`"tournament_id\\":\\`) + 35)
// }
// await browser.close();
// const fs = require("node:fs");
// fs.writeFile("test.txt", JSON.stringify(text), (err) => {
// if (err) {
// console.error(err);
// } else {
// }
// });
// }
drawMaps();
async function hltv() {
const browser = await playwright.chromium.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();
// for(let i = 0; i < 600; i++) {
await page.goto(`https://www.hltv.org/results?offset=0`);
let html = await page.content();
await page.getByText('Allow all cookies').click()
.then(async () => {
const pagePromise = context.waitForEvent('page');
page.locator('.a-reset').first().click({ button: "middle" });
const newPage = await pagePromise;
await newPage.waitForLoadState();
await saveMapResult(newPage);
})
.then(async ()=>{
await drawGames();
})
// let index = 0;
// // do {
// const searchStr = 'tournament_id';
// let indexes = [...html.matchAll(new RegExp(searchStr, 'gi'))].map(a => a.index);
// indexes = indexes.filter(x=>x !== indexes[indexes.length-1]);
// for (const index of indexes) {
// let newindex = html.indexOf(`"tournament_id\\":\\`, index);
// let tournament_id = html.slice(newindex + 19, newindex + 35);
// let slug_index = html.indexOf('"slug\\":\\"', index);
// let slug_id = html.slice(slug_index + 10, slug_index + 100);
// let url = 'https://egamersworld.com/counterstrike/match/' + tournament_id.slice(0, tournament_id.indexOf('\\')) + '/' + slug_id.slice(0, slug_id.indexOf(`\\"`));
// if(!text.includes(url)) {
// text.push(url);
// }
// }
// await browser.close();
// }
// const fs = require("node:fs");
// fs.writeFile("test.txt", JSON.stringify(text), (err) => {
// if (err) {
// console.error(err);
// } else {
// }
// });
}
hltv()
.then(()=>{
workbook.write('Excel.xlsx');
})