· last year · Feb 24, 2024, 02:55 PM
1/*
2
3Amazon captcha bypass.
4Install dependencies:
5
6npm install puppeteer @antiadmin/anticaptchaofficial
7
8Run in head-on mode:
9node amazon.js
10
11* */
12
13const anticaptcha = require("@antiadmin/anticaptchaofficial");
14const pup = require('puppeteer');
15
16//Anti-captcha.com API key
17const apiKey = 'API_KEY_HERE';
18
19//control address with Funcaptcha
20const url = 'https://www.amazon.com/aaut/verify/flex-offers/challenge?challengeType=ARKOSE_LEVEL_1&returnTo=https://www.amazon.com&headerFooter=false';
21
22let browser = null;
23let page = null;
24
25
26(async () => {
27
28 anticaptcha.setAPIKey(apiKey);
29 const balance = await anticaptcha.getBalance();
30 if (balance <= 0) {
31 console.log('Topup your anti-captcha.com balance!');
32 return;
33 } else {
34 console.log('API key balance is '+balance+', continuing');
35 // anticaptcha.shutUp(); //uncomment for silent captcha recognition
36 }
37
38
39 try {
40 antigateResult = await anticaptcha.solveAntiGateTask(
41 url,
42 'Amazon uniqueValidationId', {});
43 } catch (e) {
44 console.error("could not solve captcha: "+e.toString());
45 return;
46 }
47
48 console.log("Task result:\n", antigateResult);
49
50 const fingerPrint = antigateResult.fingerprint;
51
52 try {
53 console.log('opening browser ..');
54
55
56 let options = {
57 headless: false,
58 ignoreHTTPSErrors: true,
59 devtools: true,
60 args: [
61 '--window-size='+fingerPrint['self.screen.width']+','+fingerPrint['self.screen.height']
62 ]
63 };
64 browser = await pup.launch(options);
65
66 console.log('creating new page ..');
67 page = await browser.newPage();
68 } catch (e) {
69 console.log("could not open browser: "+e);
70 return false;
71 }
72
73 //screen size
74 console.log('setting view port to '+fingerPrint['self.screen.width']+'x'+fingerPrint['self.screen.height']);
75 await page.setViewport({width: fingerPrint['self.screen.width'], height: fingerPrint['self.screen.height']});
76
77 //user agent
78 let userAgent = '';
79 if (fingerPrint['self.navigator.userAgent']) {
80 userAgent = fingerPrint['self.navigator.userAgent'];
81 } else {
82 if (fingerPrint['self.navigator.appVersion'] && fingerPrint['self.navigator.appCodeName']) {
83 userAgent = fingerPrint['self.navigator.appCodeName'] + '/' + fingerPrint['self.navigator.appVersion']
84 }
85 }
86 console.log('setting browser user agent to '+userAgent);
87 await page.setUserAgent(userAgent);
88
89 console.log('setting cookies');
90 let cookies = [];
91 for (const name in antigateResult.cookies) {
92 cookies.push({ name: name, value: antigateResult.cookies[name], domain: antigateResult.domain })
93 }
94 await page.setCookie(...cookies);
95
96
97 try {
98 await page.goto(antigateResult.url, {
99 waitUntil: "networkidle0"
100 });
101 } catch (e) {
102 console.log('err while loading the page: '+e);
103 }
104
105
106 console.log('done');
107
108
109
110})();