This commit is contained in:
spiduler
2020-10-21 19:01:37 +09:00
parent 7334db3ceb
commit df6b5d5df5

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,8 +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)
driver.quit()
return res return res
}).then(res => { }).then(res => {
logger.debug(res, '2captcha solved') logger.debug(res, '2captcha solved')
@@ -101,8 +100,7 @@ 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)
driver.quit()
}) })
return '' return ''
} else { } else {
@@ -112,11 +110,11 @@ class SeleniumBrowser {
.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)
driver.quit()
return html return html
}) })
} else { } else {
this.pool.release(driver)
return html return html
} }
} }
@@ -135,9 +133,9 @@ class SeleniumBrowser {
} }
async close() { async close() {
// this.pool.drain().then(function () { this.pool.drain().then(function () {
// this.pool.clear(); this.pool.clear();
// }); });
} }
loggingChrome() { loggingChrome() {