dsfsdf
This commit is contained in:
@@ -41,15 +41,7 @@ class SeleniumBrowser {
|
||||
},
|
||||
destroy: (driver) => {
|
||||
logger.info('Quitting driver')
|
||||
return driver.quit().then(() => {
|
||||
logger.debug({
|
||||
spare: this.pool.spareResourceCapacity,
|
||||
size: this.pool.size,
|
||||
available: this.pool.available,
|
||||
borrowed: this.pool.borrowed,
|
||||
pending: this.pool.pending
|
||||
}, 'Pool info')
|
||||
}).catch(err => {
|
||||
return driver.quit().catch(err => {
|
||||
logger.debug({ message: err.message }, 'Quitting error')
|
||||
this.pool.release(driver)
|
||||
})
|
||||
@@ -65,7 +57,7 @@ class SeleniumBrowser {
|
||||
})
|
||||
}
|
||||
}, {
|
||||
max: 10, min: 1, testOnBorrow: true
|
||||
max: 2, min: 1, testOnBorrow: true
|
||||
});
|
||||
|
||||
this.pool.on('factoryCreateError', function (err) {
|
||||
@@ -75,6 +67,16 @@ class SeleniumBrowser {
|
||||
this.pool.on('factoryDestroyError', function (err) {
|
||||
logger.error({ message: err.message }, 'pool error')
|
||||
})
|
||||
|
||||
setInterval(() => {
|
||||
logger.debug({
|
||||
spare: this.pool.spareResourceCapacity,
|
||||
size: this.pool.size,
|
||||
available: this.pool.available,
|
||||
borrowed: this.pool.borrowed,
|
||||
pending: this.pool.pending
|
||||
}, 'Pool info')
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
getDriver() {
|
||||
@@ -92,20 +94,22 @@ class SeleniumBrowser {
|
||||
let uri = params.uri
|
||||
logger.info('URL %s', uri)
|
||||
if (uri.indexOf('://') > 3) {
|
||||
// if (this.pool) {
|
||||
return this.pool.acquire()
|
||||
.then(async driver => {
|
||||
let html = await driver.get(uri)
|
||||
.then(() => driver.findElement(By.css('body')))
|
||||
.then(body => body.getAttribute('innerHTML'))
|
||||
.then(body => body.getAttribute('innerHTML')).catch(err => {
|
||||
return false
|
||||
})
|
||||
if(!html) {
|
||||
this.pool.release(driver)
|
||||
throw new Error('Init try got Empty html')
|
||||
}
|
||||
let htmlPromise = this.isCaptchaPage(html) ? this.resolveCaptcha(driver) : this.getHtml(driver, html, params)
|
||||
html = await htmlPromise
|
||||
this.pool.destroy(driver)
|
||||
return html
|
||||
})
|
||||
// }else {
|
||||
// throw new Error('Pool is not ready')
|
||||
// }
|
||||
} else {
|
||||
throw new Error('Invalid URI - ' + uri)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user