This commit is contained in:
spiduler
2020-10-21 16:05:36 +09:00
parent 3f1d28faa6
commit 6d47b55941
2 changed files with 14 additions and 3 deletions

View File

@@ -13,6 +13,7 @@
"command-line-args": "^5.1.1",
"express": "^4.17.1",
"express-logging": "^1.1.1",
"generic-pool": "^3.7.1",
"http-status-codes": "^1.4.0",
"logops": "^2.1.1",
"node-fetch": "^2.6.1",

View File

@@ -1,9 +1,9 @@
const logger = require("logops")
, config = require('../../config')
, { Builder, Capabilities, By, Key, until } = require('selenium-webdriver')
, proxy = require('selenium-webdriver/proxy')
, url = require('url')
, fetch = require('node-fetch')
, pool = require('generic-pool')
, { Options } = require('selenium-webdriver/chrome');
class SeleniumBrowser {
@@ -15,6 +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
});
}
getDriver() {
@@ -36,13 +46,13 @@ 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'))
.then(html => this.getHtml(html))
.finally(() => {
driver.quit()
this.pool.release(driver)
})
})
} else {