This commit is contained in:
spiduler
2020-11-07 21:36:54 +09:00
parent 9cc09238b2
commit d196702961
2 changed files with 5 additions and 2 deletions

View File

@@ -102,13 +102,16 @@ class CaptchaComp {
return res
}
resolveCaptcha(driver) {
resolveCaptcha(driver, pool) {
return this.api.working ? new Promise(r => r(new Error('Resovling Catpcha'))) : this.requestResolve(driver)
.then(id => this.getAnswer(id))
.then(res => {
setTimeout(() => { this.api.working = false }, 1000 * 5 * 2)
logger.info({ result: res.request }, 'Calling captchaCallback')
return driver.executeScript('captchaCallback("' + res.request + '")').then(() => this.sleep(1000 * 5))
}).catch(err => {
logger.error({ message: err.message }, 'Resolve captcha failed')
pool.destroy(driver)
})
}
}

View File

@@ -19,7 +19,7 @@ class SeleniumBrowser {
let html = await driver.get(uri)
.then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
let p = captcha.isCaptchaPage(html) ? captcha.resolveCaptcha(driver) : this.getHtml(driver, html, params)
let p = captcha.isCaptchaPage(html) ? captcha.resolveCaptcha(driver, this.pool) : this.getHtml(driver, html, params)
html = await p
if (this.pool.isBorrowedResource(driver)) this.pool.release(driver)
return html