From 03be96b3e4e18aef689f3babf6b70c50f0fd44a2 Mon Sep 17 00:00:00 2001 From: spiduler Date: Wed, 21 Oct 2020 16:12:10 +0900 Subject: [PATCH] sdfsdf --- src/component/SeleniumBrowser.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/component/SeleniumBrowser.js b/src/component/SeleniumBrowser.js index 57e782d..72764e9 100644 --- a/src/component/SeleniumBrowser.js +++ b/src/component/SeleniumBrowser.js @@ -50,10 +50,7 @@ class SeleniumBrowser { return driver.get(uri) .then(() => driver.findElement(By.css('body'))) .then(body => body.getAttribute('innerHTML')) - .then(html => this.getHtml(html)) - .finally(() => { - this.pool.release(driver) - }) + .then(html => this.getHtml(driver, html)) }) } else { logger.info('URL %s is not valid', uri) @@ -62,15 +59,15 @@ class SeleniumBrowser { } } - async getHtml(html) { + async getHtml(driver, html) { if (html.indexOf('grecaptcha') > -1 || html.indexOf('www.google.com/recaptcha/api2/anchor') > -1) { this.isRecaptchaReseponseEmpty = true - let iframeSrc = await this.driver.findElement(By.css('#grecaptcha iframe')).getAttribute('src') + let iframeSrc = await driver.findElement(By.css('#grecaptcha iframe')).getAttribute('src') let captcha2Params = { "key": "62fc5ef52fd4befe266d224796a7ea6f", "method": "userrecaptcha", "googlekey": url.parse(iframeSrc, true).query.k, - "pageurl": await this.driver.getCurrentUrl(), + "pageurl": await driver.getCurrentUrl(), "json": 1 } let requestUrl = new url.URL('https://2captcha.com/in.php') @@ -90,12 +87,13 @@ class SeleniumBrowser { if (maxRetry == 0) break } while (res.request == 'CAPCHA_NOT_READY') this.isRecaptchaReseponseEmpty = false + this.pool.release(driver) return res }).then(res => { logger.debug(res, '2captcha solved') - this.driver.executeScript('captchaCallback("' + res.request + '")') - this.driver.wait(10000).then(d => { - this.driver.findElement(By.css('#g-recaptcha-response')).then(function (webElement) { + driver.executeScript('captchaCallback("' + res.request + '")') + driver.wait(10000).then(d => { + driver.findElement(By.css('#g-recaptcha-response')).then(function (webElement) { logger.error(res, 'Failed to overcome recaptcha') }, function (err) { logger.info('Success to overcome recaptcha') @@ -103,9 +101,11 @@ class SeleniumBrowser { }) }).catch(error => { logger.error({ message: error.message }, 'Error occured while process with 2captcha') + this.pool.release(driver) }) return '' } else { + this.pool.release(driver) return html } }