This commit is contained in:
spiduler
2020-10-23 00:19:04 +09:00
parent 2ae8dd735b
commit 60ebe537c1

View File

@@ -14,16 +14,17 @@ class SeleniumBrowser {
}
this.capabilities = Capabilities.chrome()
this.sleep = m => new Promise(r => setTimeout(r, m))
// 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.close()
driver.quit()
}
}, {
max: 10, min: 1
});
}
getDriver() {
@@ -41,15 +42,15 @@ class SeleniumBrowser {
let uri = params.uri
logger.info('URL %s', uri)
if (uri.indexOf('://') > 3) {
// return this.pool.acquire()
return this.getDriver()
return this.pool.acquire()
// return this.getDriver()
.then(async driver => {
let html = await driver.get(uri)
.then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
let htmlPromise = this.isCaptchaPage(html) ? this.resolveCaptcha(driver) : this.getHtml(driver, html, params)
html = await htmlPromise
// this.pool.release(driver)
this.pool.destroy(driver)
driver.quit()
return html
})
@@ -122,14 +123,9 @@ class SeleniumBrowser {
}
async close() {
// this.pool.drain().then(function () {
// this.pool.clear();
// })
}
loggingChrome() {
let logPath = __dirname + '/storage/chrome-logs.txt'
logger.info('Chrome logging into %s', logPath)
this.pool.drain().then(function () {
this.pool.clear();
})
}
}