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
|
* 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 {
|
||||||
|
|||||||
@@ -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",
|
||||||
@@ -91,18 +93,18 @@ class SeleniumBrowser {
|
|||||||
driver.executeScript('captchaCallback("' + res.request + '")')
|
driver.executeScript('captchaCallback("' + res.request + '")')
|
||||||
driver.wait(10000).then(d => {
|
driver.wait(10000).then(d => {
|
||||||
driver.findElement(By.css('#g-recaptcha-response'))
|
driver.findElement(By.css('#g-recaptcha-response'))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
throw new Error('Still captcha page')
|
throw new Error('Still captcha page')
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
logger.error({message: err.message}, 'Since 2captcha solved')
|
logger.error({ message: err.message }, 'Since 2captcha solved')
|
||||||
this.pool.release(driver)
|
this.pool.release(driver)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
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)
|
||||||
@@ -113,9 +115,9 @@ class SeleniumBrowser {
|
|||||||
this.pool.release(driver)
|
this.pool.release(driver)
|
||||||
return html
|
return html
|
||||||
}).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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user