From 41e42e8b574db93490a9d56f7ba79824092610b5 Mon Sep 17 00:00:00 2001 From: Anatoly Bogomolov Date: Wed, 20 Dec 2023 12:38:32 +1000 Subject: [PATCH] fixed logs --- stolichki/browser.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/stolichki/browser.py b/stolichki/browser.py index be40ccb..698cb5b 100644 --- a/stolichki/browser.py +++ b/stolichki/browser.py @@ -125,21 +125,22 @@ class StolichkiDriver(webdriver.Chrome): self.add_cookie(new_cookie) def get_network_response(self, url_mask): - logs = self.get_log("performance")[self.last_resp_index:] + logs = self.get_log("performance") + url_mask = re.compile(url_mask) + body = None + for log in filter(lambda log: self.__filter_logs(log), logs): message = json.loads(log.get("message"))['message'] request_id = message["params"]["requestId"] resp_url = message["params"]["response"]["url"] - if re.fullmatch(url_mask, resp_url) and self.last_resp_url != resp_url: - self.last_resp_index = logs.index(log) - self.last_resp_url = resp_url - body = self.execute_cdp_cmd("Network.getResponseBody", {"requestId": request_id}) - return json.loads(body['body']) + if re.fullmatch(url_mask, resp_url): + body_ = self.execute_cdp_cmd("Network.getResponseBody", {"requestId": request_id}) + body = json.loads(body_['body']) - return None + return body def __filter_logs(self, log): message = json.loads(log.get("message"))['message']