figured out what is until

This commit is contained in:
spiduler
2020-10-19 19:56:55 +09:00
parent e9ec4ab4ce
commit 645ea995d6
3 changed files with 20 additions and 6 deletions

View File

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

View File

@@ -35,14 +35,28 @@ class SeleniumBrowser {
return new Builder().forBrowser(this.config.browser).setChromeOptions(opts).build();
}
async request(uri) {
request(uri, waitElement) {
if (this.isRecaptchaReseponseEmpty) {
return ''
} else {
logger.info('URL %s', uri)
if (uri.indexOf('://') > 3) {
return this.driver.get(uri).then(d => this.driver.findElement(By.css('body')).getAttribute('innerHTML'))
return this.driver.get(uri)
// .then(() => {
// if (waitElement) {
// return this.driver.wait(until.elementIsVisible(this.driver.findElement(By.css(waitElement))), 5 * 1000)
// }
// return true
// })
.then(() => this.driver.findElement(By.css('body')))
.then(body => body.getAttribute('innerHTML'))
.then(html => this.getHtml(html))
// .catch(error => {
// logger.error({ message: error.message }, 'No image element')
// return this.driver.findElement(By.css('body'))
// .then(body => body.getAttribute('innerHTML'))
// .then(html => this.getHtml(html))
// })
} else {
logger.info('URL %s is not valid', uri)
return ''

View File

@@ -8,8 +8,8 @@ class HeadlessService {
}
real(url) {
return browser.request(url)
get(uri, waitElement) {
return browser.request(uri, waitElement)
}
close() {