-
Notifications
You must be signed in to change notification settings - Fork 160
/
crawlBattlesData.js
123 lines (100 loc) · 5.01 KB
/
crawlBattlesData.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
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
119
120
121
122
123
'use strict';
const puppeteer = require('puppeteer');
async function login(page) {
try {
//await page.click('.navbar-toggle.collapsed'); //FIRST STEP NEEDED IF PAGE SIZE TOO SMALL
//await page.waitFor(1000);
page.waitForSelector('#log_in_button > button').then(() => page.click('#log_in_button > button'))
await page.waitForSelector('#account')
.then(() => page.waitForTimeout(1000))
.then(() => page.focus('#account'))
.then(() => page.type('#account', process.env.ACCOUNT.split('@')[0], {delay: 100}))
.then(() => page.focus('#key'))
.then(() => page.type('#key', process.env.PASSWORD, {delay: 100}))
.then(() => page.click('#btn_login'))
.then(() => page.waitForTimeout(2000)
.then(() => page.waitForSelector('.modal-close-new')))
.then(() => page.click('.modal-close-new'))
} catch (e) {
console.log(e);
}
}
async function checkMana(page) {
var manas = await page.evaluate(() => {
var manaCap = document.querySelectorAll('div.mana-total > span.mana-cap')[0].innerText;
var manaUsed = document.querySelectorAll('div.mana-total > span.mana-used')[0].innerText;
var manaLeft = manaCap - manaUsed
return {manaCap, manaUsed, manaLeft};
});
console.log('manaLimit',manas);
return manas;
}
async function openSplinter() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.setViewport({
width: 1500,
height: 800,
deviceScaleFactor: 1,
});
await page.goto('https://splinterlands.com/?p=battle_history');
await page.waitForTimeout(2000);
await login(page)
await page.waitForTimeout(2000);
const [button] = await page.$x("//button[contains(., 'BATTLE LOG')]");
button ? await button.click() : null;
var battlesList = await pdocument.querySelectorAll('.history-table > table > tbody > tr');
battlesList.forEach(x=>console.log(x.querySelector('td:nth-child(8) > img').getAttribute('data-original-title')))
// var battle = await page.evaluate(() => {
// var battlesList = document.querySelectorAll('.history-table > table > tbody > tr');
// var battlesArray = [];
// for (var i = 0; i < battlesList.length; i++) {
// // battlesList[i].querySelector('td:nth-child(9) > img:nth-child(1)').click()
// // .then(()=> {
// // const battleModal = document.querySelector('div#battle_result_content');
// // battlesArray[i] = {
// // mana: battleModal.querySelector('div.mana-cap-value')[0].innerText,
// // rules: battleModal.querySelector('div.ruleset > div.rules').innerText,
// // //splinters: battleModal.querySelector('div.splinters').map().innerText, //todo
// // loser: battleModal.querySelector('div.details-team:not(.winner) > .details-player-name').innerText,
// // winner: battleModal.querySelector('div.details-team.winner > .details-player-name').innerText,
// // //loserTeam: battleModal.querySelector('div.details-team:not(.winner) > div.profile-team-container').innerText,
// // //winnerTeam: battleModal.querySelector('div.details-team:not(.winner) > div.profile-team-container').innerText,
// // link: battleModal.querySelector('div.battle-id > input').getAttribute('value'),
// // }
// // })
// battlesArray[i] = {
// //mana: battlesList[i].querySelector('td:nth-child(7)').innerText,
// rulesSet: battlesList[i].querySelector('td:nth-child(8) > img').getAttribute('data-original-title'),
// id: battlesList[i].querySelector('td:nth-child(9) > img:nth-child(3)').getAttribute('data-battle'),
// };
// }
// return battlesArray;
// });
console.log('Battles',battlesList);
// await page.waitFor(5000).then(
// ()=>{
// if (Number(mana.manaCap) > 14) {
// console.log('14plus')
// page.click('#card_162')
// .then(() => page.waitFor(1000))
// .then(() => page.click('#card_196'))
// .then(() => page.click('#card_194'));
// mana = checkMana(page).then((mana)=>console.log('mana promise', mana));
// } else {
// page.click('#card_162')
// .then(() => page.waitFor(1000))
// .then(() => page.click('#card_196'))
// .then(() => page.click('#card_194'));
// }
// });
// card id card_167
// battle_container
// btn-green
// id btnRumble
//exit battle
//button.btn-battle
//await page.waitForSelector('.algolia__results');
//await browser.close();
}
openSplinter();