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.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,7 +86,7 @@ class SeleniumBrowser {
if (maxRetry == 0) break
} while (res.request == 'CAPCHA_NOT_READY')
this.isRecaptchaReseponseEmpty = false
//this.pool.release(driver)
this.pool.release(driver)
return res
}).then(res => {
logger.debug(res, '2captcha solved')
@@ -100,18 +100,22 @@ class SeleniumBrowser {
})
}).catch(error => {
logger.error({ message: error.message }, 'Error occured while process with 2captcha')
//this.pool.release(driver)
this.pool.release(driver)
})
return ''
} else {
return driver.get(params.uri)
.then(() => driver.wait(until.elementLocated(By.css(params.waitElement))))
.then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
.then(html => {
//this.pool.release(driver)
return html
})
if (params.waitElement) {
return driver.get(params.uri)
.then(() => driver.wait(until.elementLocated(By.css(params.waitElement))))
.then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
.then(html => {
this.pool.release(driver)
return html
})
} else {
return html
}
}
}