This commit is contained in:
spiduler
2020-10-21 16:12:10 +09:00
parent 6d47b55941
commit 03be96b3e4

View File

@@ -50,10 +50,7 @@ class SeleniumBrowser {
return driver.get(uri) return driver.get(uri)
.then(() => driver.findElement(By.css('body'))) .then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML')) .then(body => body.getAttribute('innerHTML'))
.then(html => this.getHtml(html)) .then(html => this.getHtml(driver, html))
.finally(() => {
this.pool.release(driver)
})
}) })
} else { } else {
logger.info('URL %s is not valid', uri) 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) { if (html.indexOf('grecaptcha') > -1 || html.indexOf('www.google.com/recaptcha/api2/anchor') > -1) {
this.isRecaptchaReseponseEmpty = true 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 = { let captcha2Params = {
"key": "62fc5ef52fd4befe266d224796a7ea6f", "key": "62fc5ef52fd4befe266d224796a7ea6f",
"method": "userrecaptcha", "method": "userrecaptcha",
"googlekey": url.parse(iframeSrc, true).query.k, "googlekey": url.parse(iframeSrc, true).query.k,
"pageurl": await this.driver.getCurrentUrl(), "pageurl": await driver.getCurrentUrl(),
"json": 1 "json": 1
} }
let requestUrl = new url.URL('https://2captcha.com/in.php') let requestUrl = new url.URL('https://2captcha.com/in.php')
@@ -90,12 +87,13 @@ class SeleniumBrowser {
if (maxRetry == 0) break if (maxRetry == 0) break
} while (res.request == 'CAPCHA_NOT_READY') } while (res.request == 'CAPCHA_NOT_READY')
this.isRecaptchaReseponseEmpty = false this.isRecaptchaReseponseEmpty = false
this.pool.release(driver)
return res return res
}).then(res => { }).then(res => {
logger.debug(res, '2captcha solved') logger.debug(res, '2captcha solved')
this.driver.executeScript('captchaCallback("' + res.request + '")') driver.executeScript('captchaCallback("' + res.request + '")')
this.driver.wait(10000).then(d => { driver.wait(10000).then(d => {
this.driver.findElement(By.css('#g-recaptcha-response')).then(function (webElement) { driver.findElement(By.css('#g-recaptcha-response')).then(function (webElement) {
logger.error(res, 'Failed to overcome recaptcha') logger.error(res, 'Failed to overcome recaptcha')
}, function (err) { }, function (err) {
logger.info('Success to overcome recaptcha') logger.info('Success to overcome recaptcha')
@@ -103,9 +101,11 @@ class SeleniumBrowser {
}) })
}).catch(error => { }).catch(error => {
logger.error({ message: error.message }, 'Error occured while process with 2captcha') logger.error({ message: error.message }, 'Error occured while process with 2captcha')
this.pool.release(driver)
}) })
return '' return ''
} else { } else {
this.pool.release(driver)
return html return html
} }
} }