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.sleep = m => new Promise(r => setTimeout(r, m))
this.isRecaptchaReseponseEmpty = false
// this.pool = pool.createPool({
// create: () => {
// return this.getDriver();
// },
// destroy: function (driver) {
// driver.quit();
// }
// }, {
// max: 10, min: 1
// });
this.pool = pool.createPool({
create: () => {
return this.getDriver();
},
destroy: function (driver) {
driver.quit();
}
}, {
max: 10, min: 1
});
}
getDriver() {
@@ -45,7 +45,7 @@ class SeleniumBrowser {
} else {
logger.info('URL %s', uri)
if (uri.indexOf('://') > 3) {
return this.getDriver().then(driver => {
return this.pool.acquire().then(driver => {
return driver.get(uri)
.then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
@@ -86,8 +86,7 @@ class SeleniumBrowser {
if (maxRetry == 0) break
} while (res.request == 'CAPCHA_NOT_READY')
this.isRecaptchaReseponseEmpty = false
//this.pool.release(driver)
driver.quit()
this.pool.release(driver)
return res
}).then(res => {
logger.debug(res, '2captcha solved')
@@ -101,8 +100,7 @@ class SeleniumBrowser {
})
}).catch(error => {
logger.error({ message: error.message }, 'Error occured while process with 2captcha')
//this.pool.release(driver)
driver.quit()
this.pool.release(driver)
})
return ''
} else {
@@ -112,11 +110,11 @@ class SeleniumBrowser {
.then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
.then(html => {
//this.pool.release(driver)
driver.quit()
this.pool.release(driver)
return html
})
} else {
this.pool.release(driver)
return html
}
}
@@ -135,9 +133,9 @@ class SeleniumBrowser {
}
async close() {
// this.pool.drain().then(function () {
// this.pool.clear();
// });
this.pool.drain().then(function () {
this.pool.clear();
});
}
loggingChrome() {