This commit is contained in:
spiduler
2020-11-07 18:24:21 +09:00
parent 58fdc26514
commit 9981411815
2 changed files with 8 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
const logging = require("express-logging")
const logger = require("logops") const logger = require("logops")
, { By } = require('selenium-webdriver') , { By } = require('selenium-webdriver')
, url = require('url') , url = require('url')
@@ -12,7 +13,8 @@ class CaptchaComp {
in: 'https://2captcha.com/in.php', in: 'https://2captcha.com/in.php',
res: 'https://2captcha.com/res.php', res: 'https://2captcha.com/res.php',
key: "62fc5ef52fd4befe266d224796a7ea6f", key: "62fc5ef52fd4befe266d224796a7ea6f",
retryTimeout: 5000 retryTimeout: 5000,
working: false
} }
this.params = { this.params = {
in: { in: {
@@ -93,9 +95,11 @@ class CaptchaComp {
} }
resolveCaptcha(driver) { resolveCaptcha(driver) {
return this.requestResolve(driver) return this.api.working ? new Promise(r => r(new Error('Resovling Catpcha'))) : this.requestResolve(driver)
.then(id => this.getAnswer(id)) .then(id => this.getAnswer(id))
.then(res => { .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)) return driver.executeScript('captchaCallback("' + res.request + '")').then(() => this.sleep(1000 * 5))
}) })
} }

View File

@@ -19,8 +19,8 @@ class SeleniumBrowser {
let html = await driver.get(uri) let html = await 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'))
let htmlPromise = captcha.isCaptchaPage(html) ? captcha.resolveCaptcha(driver) : this.getHtml(driver, html, params) let p = captcha.isCaptchaPage(html) ? captcha.resolveCaptcha(driver) : this.getHtml(driver, html, params)
html = await htmlPromise html = await p
if (this.pool.isBorrowedResource(driver)) this.pool.release(driver) if (this.pool.isBorrowedResource(driver)) this.pool.release(driver)
return html return html
}) })