/
tutorial3.js
81 lines (62 loc) · 2.45 KB
/
tutorial3.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
const ac = require("@antiadmin/anticaptchaofficial");
const pup = require("puppeteer");
const express = require("express");
const app = express();
//serve resources from current folder
app.use(express.static(__dirname));
const server = app.listen(5000);
ac.setAPIKey('API_KEY_HERE');
ac.getBalance()
.then(balance => console.log('my balance is: '+balance))
.catch(error => console.log('an error with API key: '+error));
const login = 'mylogin';
const password = 'my strong password';
(async () => {
console.log('solving recaptcha ...');
let token = await ac.solveRecaptchaV2Proxyless('https://anti-captcha.com/', '6LdsBtAZAAAAAKD3r6e3kb4gclEXjpBXky65UbOP');
if (!token) {
console.log('something went wrong');
return;
}
// let token = 'test';
console.log('opening browser ..');
const browser = await pup.launch({ headless: false });
console.log('creating new tab ..');
const tab = await browser.newPage();
console.log('changing window size .. ');
await tab.setViewport({ width: 1360, height: 1000 });
console.log('setting interception rule ..');
await tab.setRequestInterception(true);
tab.on('request', (request) => {
if (request.resourceType() === 'script' &&
request.url().indexOf('anonymous.js') != -1) {
console.log('aborting load of '+request.url());
request.abort();
} else {
request.continue();
}
});
console.log('opening target page ..');
await tab.goto('https://anti-captcha.com/demo/?page=recaptcha_v2_anonymous_callback', { waitUntil: "networkidle0" });
console.log('injecting local script ..');
await tab.addScriptTag({url : 'http://localhost:5000/inject.js'});
await tab.waitForTimeout(3000);
console.log('filling login input ..');
await tab.$eval('#login', (element, login) => {
element.value = login;
element.dispatchEvent(new Event('change'));
}, login);
console.log('filling password input');
await tab.$eval('#pass', (element, password) => {
element.value = password;
}, password);
console.log('setting recaptcha g-response ...');
await tab.evaluate((token) => {
checkCaptcha(token);
}, token);
await tab.waitForNavigation({ waitUntil: "networkidle0" })
console.log('making a screenshot ...');
await tab.screenshot({ path: 'screenshot.png' });
//console.log('closing browser .. ');
//await browser.close();
})();