try catch when 2captcha connection failed

This commit is contained in:
2022-09-10 11:36:31 +02:00
parent af9d199b7f
commit b00055f8d9
3 changed files with 33 additions and 22 deletions
+4
View File
@@ -17,3 +17,7 @@ adb -s 76a3ac8d shell am start -n com.android.chrome/com.google.android.apps.chr
adb -s 47e7e36b shell pm clear com.android.chrome
adb -s 47e7e36b shell am set-debug-app --persistent com.android.chrome
adb -s 47e7e36b shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
#asus tab
adb -s 751005221815 shell pm clear com.android.chrome
adb -s 751005221815 shell am set-debug-app --persistent com.android.chrome
adb -s 751005221815 shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
+5 -4
View File
@@ -1,6 +1,6 @@
const {_android: android, devices} = require("playwright");
const SolveCaptcha = require("./SolveCaptcha");
const {SolveCaptcha, TWO_CAPTCHA_CONNECTION_FAILED} = require("./SolveCaptcha");
const ReserveResultPojo = require("../models/ReserveResultPojo");
const PublishType = require("../models/PublishType");
@@ -174,13 +174,14 @@ class CommandorPage {
async clickValid(page) {
await delay(getRandomWaitTime())
try {
if (!this.page.isClosed()){
this.page.evaluate(() => {
document.getElementsByClassName("btn")[0].focus();
})
await delay(getRandomWaitTime())
this.page.evaluate(() => {
document.getElementsByClassName("btn")[0].click();
})
})}
} catch (e) {
console.log(e)
}
@@ -194,7 +195,7 @@ class CommandorPage {
this.captchaSolver = new SolveCaptcha(page);
await this.captchaSolver.start((solution) => {
console.log("solution is: " + solution);
if (solution !== ERROR_CAPTCHA_UNSOLVABLE) {
if (solution !== ERROR_CAPTCHA_UNSOLVABLE&&solution!==TWO_CAPTCHA_CONNECTION_FAILED) {
try {
if (!page.isClosed()){
page.evaluate((solution) => {
@@ -217,7 +218,7 @@ class CommandorPage {
if (content.toString().includes(captcha_url)) {
await this.checkAudioBtn();
console.log("we are blocked");
console.log("发现datadome");
} else {
if (currentPage.url() === RDV_URL) {
await this.fillFields(this.page);
+8 -2
View File
@@ -1,5 +1,6 @@
const axios = require("axios");
const CAPCHA_NOT_READY = "CAPCHA_NOT_READY";
const TWO_CAPTCHA_CONNECTION_FAILED = "TWO_CAPTCHA_CONNECTION_FAILED";
const REGEX_DATA_SITE_KEY = "data-sitekey=[\"a-z0-9A-Z]+";
const API_KEY = "d66aaf490d8aa424a5175e1fbd1aadea";
const SITE_KEY = "6LdUViwUAAAAAOBJjtMsmKc9C7200Djd31w2mCs7";
@@ -24,8 +25,8 @@ class SolveCaptcha {
async solve_captcha(site_key, handle_solution_received) {
console.log("solve_captcha(), for " + this.page.url())
try {
let url_get = `http://2captcha.com/in.php?key=${API_KEY}&method=userrecaptcha&googlekey=${site_key}&pageurl=${this.page.url()}`;
let res = await axios.get(url_get)
console.log(`statusCode: ${res.status}`);
console.log(res);
@@ -41,6 +42,11 @@ class SolveCaptcha {
})
}
handle_solution_received(solution)
}catch (e) {
console.log(e)
handle_solution_received(TWO_CAPTCHA_CONNECTION_FAILED)
}
}
async get_solution(catcha_id, onSolutionFound) {
@@ -68,4 +74,4 @@ class SolveCaptcha {
}
}
module.exports = SolveCaptcha
module.exports = {SolveCaptcha, TWO_CAPTCHA_CONNECTION_FAILED}