This commit is contained in:
spiduler
2020-10-21 17:41:26 +09:00
parent 3bcd85f510
commit e2916b86e4

View File

@@ -15,16 +15,16 @@ class SeleniumBrowser {
this.capabilities = Capabilities.chrome() this.capabilities = Capabilities.chrome()
this.sleep = m => new Promise(r => setTimeout(r, m)) this.sleep = m => new Promise(r => setTimeout(r, m))
this.isRecaptchaReseponseEmpty = false this.isRecaptchaReseponseEmpty = false
// this.pool = pool.createPool({ this.pool = pool.createPool({
// create: () => { create: () => {
// return this.getDriver(); return this.getDriver();
// }, },
// destroy: function (driver) { destroy: function (driver) {
// driver.quit(); driver.quit();
// } }
// }, { }, {
// max: 10, min: 1 max: 10, min: 1
// }); });
} }
getDriver() { getDriver() {
@@ -45,7 +45,7 @@ class SeleniumBrowser {
} else { } else {
logger.info('URL %s', uri) logger.info('URL %s', uri)
if (uri.indexOf('://') > 3) { if (uri.indexOf('://') > 3) {
return this.getDriver().then(driver => { return this.pool.acquire().then(driver => {
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'))
@@ -86,7 +86,7 @@ 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) this.pool.release(driver)
return res return res
}).then(res => { }).then(res => {
logger.debug(res, '2captcha solved') logger.debug(res, '2captcha solved')
@@ -100,18 +100,22 @@ 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) this.pool.release(driver)
}) })
return '' return ''
} else { } else {
if (params.waitElement) {
return driver.get(params.uri) return driver.get(params.uri)
.then(() => driver.wait(until.elementLocated(By.css(params.waitElement)))) .then(() => driver.wait(until.elementLocated(By.css(params.waitElement))))
.then(() => driver.findElement(By.css('body'))) .then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML')) .then(body => body.getAttribute('innerHTML'))
.then(html => { .then(html => {
//this.pool.release(driver) this.pool.release(driver)
return html return html
}) })
} else {
return html
}
} }
} }