This commit is contained in:
spiduler
2020-10-21 17:18:00 +09:00
parent 03be96b3e4
commit 6e6dcbf6d6

View File

@@ -40,7 +40,6 @@ class SeleniumBrowser {
async request(params) { async request(params) {
let uri = params.uri let uri = params.uri
let waitElement = params.waitElement
if (this.isRecaptchaReseponseEmpty) { if (this.isRecaptchaReseponseEmpty) {
return '' return ''
} else { } else {
@@ -50,7 +49,7 @@ class SeleniumBrowser {
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(driver, html)) .then(html => this.getHtml(driver, html, params))
}) })
} else { } else {
logger.info('URL %s is not valid', uri) logger.info('URL %s is not valid', uri)
@@ -59,7 +58,7 @@ class SeleniumBrowser {
} }
} }
async getHtml(driver, html) { 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
let iframeSrc = await driver.findElement(By.css('#grecaptcha iframe')).getAttribute('src') let iframeSrc = await driver.findElement(By.css('#grecaptcha iframe')).getAttribute('src')
@@ -105,8 +104,14 @@ class SeleniumBrowser {
}) })
return '' return ''
} else { } else {
return driver.get(params.uri)
.then(() => driver.wait(until.elementLocated(By.css(params.waitElement))))
.then(() => driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
.then(html => {
this.pool.release(driver) this.pool.release(driver)
return html return html
})
} }
} }