-
Notifications
You must be signed in to change notification settings - Fork 1
/
gibdd_fines.js
129 lines (116 loc) · 4.02 KB
/
gibdd_fines.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
124
125
126
127
128
129
const puppeteer = require('puppeteer')
const { getV3Token, reportAnswer } = require('./solverv3.js')
var qs = require('querystring')
const targetUrl = 'https://xn--90adear.xn--p1ai/check/fines'
const attemptsLimit = 10
const interceptUrls = [
{
url: 'https://xn--b1afk4ade.xn--90adear.xn--p1ai/proxy/check/fines',
action: 'check_fines',
attempts: 0,
success: false
}
]
let params = {
action: undefined,
min_score: '0.9',
googlekey: '6Lc66nwUAAAAANZvAnT-OK4f4D_xkdzw5MLtAYFL',
pageurl: 'https://xn--90adear.xn--p1ai/check/fines'
// pageurl: 'http://xn--b1afk4ade.xn--90adear.xn--p1ai/'
}
const formFillData = {
checkFinesRegnum: 'К097АВ',
checkFinesRegreg: '136',
checkFinesStsnum: '3627162475'
}
const browserParams = {
headless: false,
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
],
// executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' //let's use real chrome instead of Chromium
}
const checkUrl = (url) => {
let match = interceptUrls.find(u => u.url === url)
if (!match) return false
return match
}
let currentLink = 0
let doThat = async (browser) => {
const page = await browser.newPage()
const clickTheLink = async (ind) => {
try {
await page.evaluate(i => {
if (i < document.querySelectorAll('a.checker').length) {
document.querySelectorAll('a.checker')[i].click()
}
}, ind)
} catch (e) {
console.log(e)
}
}
page.on('request', async (r) => {
let urlObj = checkUrl(r.url())
if (r.method() === 'POST' && urlObj) {
params.action = urlObj.action
let captcha = await getV3Token(params)
try {
console.log('request intercepted')
const initData = r.postData()
const parsedData = qs.parse(initData)
parsedData.reCaptchaToken = captcha.token
qs.stringify(parsedData)
await r.continue({ postData: qs.stringify(parsedData) })
urlObj.attempts++
console.log('Link: ' + currentLink + ' attempt: ' + urlObj.attempts)
const finalResponse = await page.waitForResponse(response => response.url() === r.url() && response.status() === 200, { timeout: 180 * 1000 })
const data = await finalResponse.json()
console.log(data)
if (data.code === 200) {
urlObj.success = true
console.log("passed: " + captcha.id)
await reportAnswer(captcha.id, true)
await page.close()
} else {
console.log("failed: " + captcha.id)
await reportAnswer(captcha.id, false)
await page.waitFor(500)
if (urlObj.attempts < attemptsLimit) {
clickTheLink(currentLink)
}
}
} catch (e) {
console.log('Huston we have a problem: ' + e)
}
} else {
r.continue()
}
})
await page.setViewport({
width: 1200,
height: 1000
})
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36')
await page.setRequestInterception(true)
await page.goto(targetUrl);
await page.waitFor(2500)
try {
await page.focus('#checkFinesRegnum')
for (var field in formFillData) {
await page.focus('#' + field)
await page.waitFor(500)
await page.type('#' + field, formFillData[field], { delay: 100 })
}
} catch (e) {
await page.goBack()
await page.goForward()
}
clickTheLink(currentLink)
}
puppeteer.launch(browserParams)
.then((browser) => {
doThat(browser).catch(e => {
console.log(e)
})
})