From ee5f6a8c6b49ed7419eeb9e5fc3da3ec9ba3a475 Mon Sep 17 00:00:00 2001 From: PAN Lei Date: Thu, 8 Sep 2022 11:33:52 +0200 Subject: [PATCH] add regex for url --- src/workers/CommandorPage.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 165fb7b..4f08cfa 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -28,6 +28,7 @@ const TOO_MANY_REQUEST_ERROR_MESSAGE = "Due to a large number of requests" const TOO_MANY_REQUEST_ERROR_MESSAGE_FR = "Suite à un trop grand nombre de demandes" const CAPTCHA_ERROR_MESSAGE = "Error verifying captcha, please try again" const CAPTCHA_ERROR_MESSAGE_FR = "La vérification du captcha a échoué" +REGEX_RDV_URL = "https:\/\/rendezvousparis\.hermes\.com\/client\/register\/[A-Z0-9]+" function delay(delayInms) { return new Promise(resolve => { @@ -66,6 +67,10 @@ class CommandorPage { this.page.on("load", (loadedPage) => { this.onPageLoad(loadedPage) }) + + this.page.on("response", (response) => { + this.onResponse(response) + }) await this.page.goto(RDV_URL); //wait 10 mins // Close the device. @@ -209,6 +214,13 @@ class CommandorPage { } } + async onResponse(response) { + let rex = new RegExp(REGEX_RDV_URL) + if (rex.test(response.url)) { + console.log("rdv url found:" + response.url) + } + } + async push_message_to_queue(publishType) { let url = this.page.url(); let splitedUrl = url.split("/"); @@ -222,6 +234,8 @@ class CommandorPage { await this.mongoManager.saveReserveToDb(reserve.to_mongo_dict()) this.isTerminated = true } + + } module.exports = CommandorPage \ No newline at end of file