-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.js
88 lines (68 loc) · 2.56 KB
/
lib.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
const puppeteer = require('puppeteer')
async function getCreditClubScore({ login, pass, word }) {
const browser = await puppeteer.launch({args: ['--no-sandbox']})
const page = await browser.newPage()
await page.goto('https://clubs.moneysavingexpert.com/creditclub/login', {
waitUntil: 'networkidle2',
})
await page.waitFor(1000)
await page.evaluate(
(eLogin, ePass) => {
var evt = document.createEvent('HTMLEvents')
evt.initEvent('change', true, true)
document.querySelector('input[name=email]').value = eLogin
document.querySelector('input[name=email]').dispatchEvent(evt)
document.querySelector('input[name=password]').value = ePass
document.querySelector('input[name=password]').dispatchEvent(evt)
document.querySelector('button[type=submit]').click()
},
login,
pass,
)
await page.waitForNavigation()
await page.evaluate(eWord => {
var evt = document.createEvent('HTMLEvents')
evt.initEvent('change', true, true)
const w1 = document.querySelector('#memorableWordChar1')
const w2 = document.querySelector('#memorableWordChar2')
const w3 = document.querySelector('#memorableWordChar3')
w1.value = eWord[+w1.placeholder.slice(0, 1) - 1]
w2.value = eWord[+w2.placeholder.slice(0, 1) - 1]
w3.value = eWord[+w3.placeholder.slice(0, 1) - 1]
w1.dispatchEvent(evt)
w2.dispatchEvent(evt)
w3.dispatchEvent(evt)
document.querySelector('#sign-in-2FA-authentication').click()
}, word)
await page.waitForNavigation()
try {
await page.waitForSelector('form[name=reconfirmDetails]', {
timeout: 5000,
})
await page.evaluate(() => {
document.querySelector('#details-correct-yes').click()
document.querySelector('#reconfirm-details').click()
})
} catch (e) {}
await page.waitForSelector('.experian-score__score-text--large')
const report_date = await page.evaluate(
() => document.querySelector('.text--no-margin').textContent,
)
const updated_date = await page.evaluate(
() => document.querySelectorAll('.text--no-margin')[1].textContent,
)
const creditScore = await page.evaluate(
() => document.querySelector('.experian-score__score-text--large').textContent,
)
let todayDate = new Date()
let reportDate = new Date(updated_date.slice(17))
let daysUntil = Math.ceil((reportDate - todayDate) / (1000 * 60 * 60 * 24))
const output = {
report_date: report_date.slice(15),
updated_date: daysUntil,
score: creditScore,
}
await browser.close()
return output
}
module.exports = getCreditClubScore