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']