3

Maybe someone knows how to get data from Response in DevTools with Selenium?

https://i.stack.imgur.com/T9ALa.png

I don`t know how to get response data.

  • 1
    You can get response of XHR by sending appropriate HTTP request directly with `python-requests` and then handle response as JSON – Andersson Jul 30 '18 at 17:28

2 Answers2

0

It's as easy as this:

response = driver.execute_script(javascript)

Now response has what was returned by the script!

K. Dackow
  • 456
  • 1
  • 3
  • 15
  • I am not sure how to get this, and there is a chance that it isn't possible. This is because some of the features of the DevTools interface require being in a DevTools console to run, which Selenium does not allow, and which requires creating a DevTools [extension][https://developer.chrome.com/extensions/devtools#creating] – K. Dackow Jul 30 '18 at 15:59
  • Another thing you may consider is using MahiMahi [http://mahimahi.mit.edu/] or Polly.js [https://netflix.github.io/pollyjs/#/] to save data from requests. (I know MahiMahi works well with Selenium, as I am currently using it) – K. Dackow Jul 30 '18 at 16:00
0

What you are asking for is the HTTP response of a specific request happening in the website. Getting performance info is possible by executing javascript but you won't be able to get the response of all the requests which is happening in the page, atleast from what I know.

However, if you already know the exact request (or you can get it by this way), you can get the response easily by simulating that request in python. Here is an example -

import requests

headers = {
   "your_header_keys" : "your_header_values"
}

data = [
  "your_request_body"
]

response = requests.post('your_url', headers=headers, data=data)
Shivam Mishra
  • 1,731
  • 2
  • 11
  • 29