I use Selenium to react to the reception of data following a GET request from a website.
The API called by the website is not public, so if I use the URL of the request to retrieve the data, I get {"message":"Unauthenticated."}
.
All I've managed to do so far is to retrieve the header of the response.
I found here that using driver.execute_cdp_cmd('Network.getResponseBody', {...})
might be a solution to my problem.
Here is a sample of my code:
import json
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.CHROME
capabilities["goog:loggingPrefs"] = {"performance": "ALL"}
driver = webdriver.Chrome(
r"./chromedriver",
desired_capabilities=capabilities,
)
def processLog(log):
log = json.loads(log["message"])["message"]
if ("Network.response" in log["method"] and "params" in log.keys()):
headers = log["params"]["response"]
body = driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': log["params"]["requestId"]})
print(json.dumps(body, indent=4, sort_keys=True))
return log["params"]
logs = driver.get_log('performance')
responses = [processLog(log) for log in logs]
Unfortunately, the driver.execute_cdp_cmd('Network.getResponseBody', {...})
returns:
unknown error: unhandled inspector error: {"code":-32000,"message":"No resource with given identifier found"}
Do you know what I am missing?
Do you have any idea on how to retrieve the response body?
Thank you for your help!
getResponseBody
I still get exactly your original error – Scad