-
Notifications
You must be signed in to change notification settings - Fork 36
/
amazon.js
110 lines (81 loc) · 2.95 KB
/
amazon.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
/*
Amazon captcha bypass.
Install dependencies:
npm install puppeteer @antiadmin/anticaptchaofficial
Run in head-on mode:
node amazon.js
* */
const anticaptcha = require("@antiadmin/anticaptchaofficial");
const pup = require('puppeteer');
//Anti-captcha.com API key
const apiKey = 'API_KEY_HERE';
//control address with Funcaptcha
const url = 'https://www.amazon.com/aaut/verify/flex-offers/challenge?challengeType=ARKOSE_LEVEL_1&returnTo=https://www.amazon.com&headerFooter=false';
let browser = null;
let page = null;
(async () => {
anticaptcha.setAPIKey(apiKey);
const balance = await anticaptcha.getBalance();
if (balance <= 0) {
console.log('Topup your anti-captcha.com balance!');
return;
} else {
console.log('API key balance is '+balance+', continuing');
// anticaptcha.shutUp(); //uncomment for silent captcha recognition
}
try {
antigateResult = await anticaptcha.solveAntiGateTask(
url,
'Amazon uniqueValidationId', {});
} catch (e) {
console.error("could not solve captcha: "+e.toString());
return;
}
console.log("Task result:\n", antigateResult);
const fingerPrint = antigateResult.fingerprint;
try {
console.log('opening browser ..');
let options = {
headless: false,
ignoreHTTPSErrors: true,
devtools: true,
args: [
'--window-size='+fingerPrint['self.screen.width']+','+fingerPrint['self.screen.height']
]
};
browser = await pup.launch(options);
console.log('creating new page ..');
page = await browser.newPage();
} catch (e) {
console.log("could not open browser: "+e);
return false;
}
//screen size
console.log('setting view port to '+fingerPrint['self.screen.width']+'x'+fingerPrint['self.screen.height']);
await page.setViewport({width: fingerPrint['self.screen.width'], height: fingerPrint['self.screen.height']});
//user agent
let userAgent = '';
if (fingerPrint['self.navigator.userAgent']) {
userAgent = fingerPrint['self.navigator.userAgent'];
} else {
if (fingerPrint['self.navigator.appVersion'] && fingerPrint['self.navigator.appCodeName']) {
userAgent = fingerPrint['self.navigator.appCodeName'] + '/' + fingerPrint['self.navigator.appVersion']
}
}
console.log('setting browser user agent to '+userAgent);
await page.setUserAgent(userAgent);
console.log('setting cookies');
let cookies = [];
for (const name in antigateResult.cookies) {
cookies.push({ name: name, value: antigateResult.cookies[name], domain: antigateResult.domain })
}
await page.setCookie(...cookies);
try {
await page.goto(antigateResult.url, {
waitUntil: "networkidle0"
});
} catch (e) {
console.log('err while loading the page: '+e);
}
console.log('done');
})();