dsfdsf
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
"command-line-args": "^5.1.1",
|
"command-line-args": "^5.1.1",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-logging": "^1.1.1",
|
"express-logging": "^1.1.1",
|
||||||
|
"generic-pool": "^3.7.1",
|
||||||
"http-status-codes": "^1.4.0",
|
"http-status-codes": "^1.4.0",
|
||||||
"logops": "^2.1.1",
|
"logops": "^2.1.1",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const logger = require("logops")
|
const logger = require("logops")
|
||||||
, config = require('../../config')
|
, config = require('../../config')
|
||||||
, { Builder, Capabilities, By, Key, until } = require('selenium-webdriver')
|
, { Builder, Capabilities, By, Key, until } = require('selenium-webdriver')
|
||||||
, proxy = require('selenium-webdriver/proxy')
|
|
||||||
, url = require('url')
|
, url = require('url')
|
||||||
, fetch = require('node-fetch')
|
, fetch = require('node-fetch')
|
||||||
|
, pool = require('generic-pool')
|
||||||
, { Options } = require('selenium-webdriver/chrome');
|
, { Options } = require('selenium-webdriver/chrome');
|
||||||
|
|
||||||
class SeleniumBrowser {
|
class SeleniumBrowser {
|
||||||
@@ -15,6 +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({
|
||||||
|
create: () => {
|
||||||
|
return this.getDriver();
|
||||||
|
},
|
||||||
|
destroy: function (driver) {
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
max: 10, min: 1
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getDriver() {
|
getDriver() {
|
||||||
@@ -36,13 +46,13 @@ 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'))
|
||||||
.then(html => this.getHtml(html))
|
.then(html => this.getHtml(html))
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
driver.quit()
|
this.pool.release(driver)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user