sdfsdfdsf

This commit is contained in:
spiduler
2020-10-22 10:35:43 +09:00
parent 7c604ed2a0
commit 478492187e
2 changed files with 17 additions and 18 deletions

View File

@@ -63,10 +63,7 @@ process.on('SIGTERM', exitHandler.bind(null, { cleanup: true }));
* request handler * request handler
*/ */
app.post('/', async (req, res, next) => { app.post('/', async (req, res, next) => {
browser.get(req.body).then(html => { browser.get(req.body).then(html => res.send(html)).catch(e => {
if (html) res.send(html)
else throw new Error('Emtpy html')
}).catch(e => {
if (e instanceof NoSuchSessionError) { if (e instanceof NoSuchSessionError) {
logger.error({ reason: e.message, url: req.url }, 'Browser session expired') logger.error({ reason: e.message, url: req.url }, 'Browser session expired')
} else { } else {

View File

@@ -41,7 +41,7 @@ class SeleniumBrowser {
async request(params) { async request(params) {
let uri = params.uri let uri = params.uri
if (this.isRecaptchaReseponseEmpty) { if (this.isRecaptchaReseponseEmpty) {
return '' throw new Error('2captcha still processing')
} else { } else {
logger.info('URL %s', uri) logger.info('URL %s', uri)
if (uri.indexOf('://') > 3) { if (uri.indexOf('://') > 3) {
@@ -52,8 +52,7 @@ class SeleniumBrowser {
.then(html => this.getHtml(driver, html, params)) .then(html => this.getHtml(driver, html, params))
}) })
} else { } else {
logger.info('URL %s is not valid', uri) throw new Error('Invalid URI - ' + uri)
return ''
} }
} }
} }
@@ -61,6 +60,9 @@ class SeleniumBrowser {
async getHtml(driver, html, params) { async getHtml(driver, html, params) {
if (html.indexOf('grecaptcha') > -1 || html.indexOf('www.google.com/recaptcha/api2/anchor') > -1) { if (html.indexOf('grecaptcha') > -1 || html.indexOf('www.google.com/recaptcha/api2/anchor') > -1) {
this.isRecaptchaReseponseEmpty = true this.isRecaptchaReseponseEmpty = true
setTimeout(() => {
this.isRecaptchaReseponseEmpty = false
}, 1000 * 60)
let iframeSrc = await driver.findElement(By.css('#grecaptcha iframe')).getAttribute('src') let iframeSrc = await driver.findElement(By.css('#grecaptcha iframe')).getAttribute('src')
let captcha2Params = { let captcha2Params = {
"key": "62fc5ef52fd4befe266d224796a7ea6f", "key": "62fc5ef52fd4befe266d224796a7ea6f",
@@ -102,7 +104,7 @@ class SeleniumBrowser {
logger.error({ message: error.message }, 'Error occured while process with 2captcha') logger.error({ message: error.message }, 'Error occured while process with 2captcha')
this.pool.release(driver) this.pool.release(driver)
}) })
return '' throw new Error('2captcha processing')
} else { } else {
if (params.waitElement) { if (params.waitElement) {
return driver.get(params.uri) return driver.get(params.uri)
@@ -115,7 +117,7 @@ class SeleniumBrowser {
}).catch(err => { }).catch(err => {
logger.error({ message: err.message }, 'Wait element failed') logger.error({ message: err.message }, 'Wait element failed')
this.pool.release(driver) this.pool.release(driver)
return '' throw new Error('2captcha processing')
}) })
} else { } else {
this.pool.release(driver) this.pool.release(driver)
@@ -139,7 +141,7 @@ class SeleniumBrowser {
async close() { async close() {
this.pool.drain().then(function () { this.pool.drain().then(function () {
this.pool.clear(); this.pool.clear();
}); })
} }
loggingChrome() { loggingChrome() {