Selenium Python - Get Network response body Selenium Python - Get Network response body selenium selenium

Selenium Python - Get Network response body


In order to retrieve response body, you have to listen specifically to Network.responseReceived:

def processLog(log):    log = json.loads(log["message"])["message"]    if ("Network.responseReceived" in log["method"] and "params" in log.keys()):        body = driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': log["params"]["requestId"]})

However, I ended using a different approach relying on requests. I just retrieved the authorization token from the browser console (Network > Headers > Request Headers > Authorization) and used it to get the data I wanted:

import requestsdef get_data():    url = "<your_url>"    headers = {        "Authorization": "Bearer <your_access_token>",        "Content-type": "application/json"    }    params = {        key: value,        ...    }    r = requests.get(url, headers = headers, params = params)    if r.status_code == 200:        return r.json()