sdfsdfdsf
This commit is contained in:
5
index.js
5
index.js
@@ -63,10 +63,7 @@ process.on('SIGTERM', exitHandler.bind(null, { cleanup: true }));
|
||||
* request handler
|
||||
*/
|
||||
app.post('/', async (req, res, next) => {
|
||||
browser.get(req.body).then(html => {
|
||||
if (html) res.send(html)
|
||||
else throw new Error('Emtpy html')
|
||||
}).catch(e => {
|
||||
browser.get(req.body).then(html => res.send(html)).catch(e => {
|
||||
if (e instanceof NoSuchSessionError) {
|
||||
logger.error({ reason: e.message, url: req.url }, 'Browser session expired')
|
||||
} else {
|
||||
|
||||
@@ -41,7 +41,7 @@ class SeleniumBrowser {
|
||||
async request(params) {
|
||||
let uri = params.uri
|
||||
if (this.isRecaptchaReseponseEmpty) {
|
||||
return ''
|
||||
throw new Error('2captcha still processing')
|
||||
} else {
|
||||
logger.info('URL %s', uri)
|
||||
if (uri.indexOf('://') > 3) {
|
||||
@@ -52,8 +52,7 @@ class SeleniumBrowser {
|
||||
.then(html => this.getHtml(driver, html, params))
|
||||
})
|
||||
} else {
|
||||
logger.info('URL %s is not valid', uri)
|
||||
return ''
|
||||
throw new Error('Invalid URI - ' + uri)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +60,9 @@ class SeleniumBrowser {
|
||||
async getHtml(driver, html, params) {
|
||||
if (html.indexOf('grecaptcha') > -1 || html.indexOf('www.google.com/recaptcha/api2/anchor') > -1) {
|
||||
this.isRecaptchaReseponseEmpty = true
|
||||
setTimeout(() => {
|
||||
this.isRecaptchaReseponseEmpty = false
|
||||
}, 1000 * 60)
|
||||
let iframeSrc = await driver.findElement(By.css('#grecaptcha iframe')).getAttribute('src')
|
||||
let captcha2Params = {
|
||||
"key": "62fc5ef52fd4befe266d224796a7ea6f",
|
||||
@@ -94,7 +96,7 @@ class SeleniumBrowser {
|
||||
.then(() => {
|
||||
throw new Error('Still captcha page')
|
||||
}).catch(err => {
|
||||
logger.error({message: err.message}, 'Since 2captcha solved')
|
||||
logger.error({ message: err.message }, 'Since 2captcha solved')
|
||||
this.pool.release(driver)
|
||||
})
|
||||
})
|
||||
@@ -102,7 +104,7 @@ class SeleniumBrowser {
|
||||
logger.error({ message: error.message }, 'Error occured while process with 2captcha')
|
||||
this.pool.release(driver)
|
||||
})
|
||||
return ''
|
||||
throw new Error('2captcha processing')
|
||||
} else {
|
||||
if (params.waitElement) {
|
||||
return driver.get(params.uri)
|
||||
@@ -113,9 +115,9 @@ class SeleniumBrowser {
|
||||
this.pool.release(driver)
|
||||
return html
|
||||
}).catch(err => {
|
||||
logger.error({message: err.message}, 'Wait element failed')
|
||||
logger.error({ message: err.message }, 'Wait element failed')
|
||||
this.pool.release(driver)
|
||||
return ''
|
||||
throw new Error('2captcha processing')
|
||||
})
|
||||
} else {
|
||||
this.pool.release(driver)
|
||||
@@ -139,7 +141,7 @@ class SeleniumBrowser {
|
||||
async close() {
|
||||
this.pool.drain().then(function () {
|
||||
this.pool.clear();
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
loggingChrome() {
|
||||
|
||||
Reference in New Issue
Block a user