-
Notifications
You must be signed in to change notification settings - Fork 38
/
olx.ua.js
200 lines (147 loc) · 5.03 KB
/
olx.ua.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//npm install puppeteer fs @antiadmin/anticaptchaofficial
// update your login credentials
// run with command: "node olx.ua.js"
const anticaptcha = require("@antiadmin/anticaptchaofficial");
const pup = require("puppeteer");
//API key for anti-captcha.com
const anticaptchaAPIKey = 'API_KEY_HERE';
//access data
const url = 'https://www.olx.ua/account/#register';
const sitekey = '6Le48QAaAAAAAId_ao_tJuFtMhPEoRr8h3BmlS7H';
const login = makeid(15)+'@gmail.com';
const password = makepass(12)+Math.round(Math.random()*100);
//uncomment and fill if you want to use proxy
// const proxyAddress = 'xxx.yyy.zzz.ddd';
// const proxyPort = 1234;
// const proxyUser = 'user';
// const proxyPassword = 'login';
const proxyAddress = null;
const proxyPort = null;
const proxyUser = null;
const proxyPassword = null;
let browser = null;
let page = null;
let token = null;
(async () => {
anticaptcha.setAPIKey(anticaptchaAPIKey);
const balance = await anticaptcha.getBalance();
if (balance <= 0) {
console.log('Buy your anticaptcha balance!');
return;
} else {
console.log('API key balance is '+balance+', continuing');
anticaptcha.shutUp(); //uncomment for silent captcha recognition
}
console.log('registering account with login '+login+' and password '+password);
try {
console.log('opening browser ..');
let options = {
headless: false,
ignoreHTTPSErrors: true,
devtools: true
};
if (proxyAddress && proxyPort) {
options["args"] = ['--proxy-server='+proxyAddress+':'+proxyPort];
}
console.log(options);
browser = await pup.launch(options);
console.log('creating new page ..');
page = await browser.newPage();
} catch (e) {
failCallback("could not open browser: "+e);
return false;
}
//screen size
await page.setViewport({width: 1360, height: 1000});
//setting proxy login and password
if (proxyPassword && proxyUser) {
console.log('setting proxy authentication .. ('+proxyUser+":"+proxyPassword+')');
await page.authenticate({
username: proxyUser,
password: proxyPassword,
});
}
try {
await page.goto(url, {
waitUntil: "networkidle0"
});
} catch (e) {
console.log('err while loading the page: '+e);
}
console.log('solving captcha');
try {
token = await anticaptcha.solveRecaptchaV3Enterprise(
url,
sitekey,
0.9,
'register');
} catch (e) {
failCallback("could not solve captcha");
return;
}
console.log('token is ready: '+token);
console.log('filling form ..');
const loginInput= await page.$(`#userEmailPhoneRegister`)
await loginInput.focus();
await page.type(`#userEmailPhoneRegister`,login)
await delay(1000);
const passwordInput= await page.$(`#userPassRegister`)
await passwordInput.focus();
await page.type(`#userPassRegister`,password)
await delay(1000);
await page.$eval('input[name="register[rules]"]', check => check.checked = true);
const injectHTML = '<textarea name="g-recaptcha-response">'+token+'</textarea>';
await page.$eval('#registerForm > div:nth-child(10)', (element, injectHTML) => {
element.innerHTML = injectHTML;
}, injectHTML);
await delay(3000);
try {
await page.evaluate(async () => {
onSubmit();
});
} catch (e) {
failCallback("could not submit form: "+e);
}
await delay(10000);
const failKeyword = 'Произошла ошибка во время регистрации аккаунта';
let htmlContent = await page.$eval('*', el => el.innerText);
if (htmlContent.indexOf(failKeyword) !== -1) {
failCallback('Failed to register');
} else {
successCallback('registered account with login '+login+' and password '+password);
}
console.log('done');
})();
function delay(time) {
return new Promise(function(resolve) {
setTimeout(resolve, time)
});
}
function successCallback(result) {
console.log('Successfully passed: '+result);
// console.log('closing browser .. ');
// browser.close();
}
function failCallback(code) {
console.log('Failed to pass: '+code);
// console.log('closing browser .. ');
// browser.close();
}
function makeid(length) {
let result = '';
let characters = 'abcdefghijklmnopqrstuvwxyz';
let charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
function makepass(length) {
let result = '';
let characters = 'abcdefghijklmnopqrstuvwxyzQWERTYUIOPASDFGHJKLZXCVBNM12345678901234567890';
let charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}