How to get data from Response with Python Selenium in DevTools - python-3.x

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.

It's as easy as this:
response = driver.execute_script(javascript)
Now response has what was returned by the script!

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)

Related

Only return the response status from a axios GET request?

I`m writing tests in playwright where I check if all the links on my web page are valid.
I'm using Axios to get the responses and because I have a lot of links I want to expedite the tests as much as possible, so I want to receive only the status response code from Axios without the response data, is this in any way possible with Axios or maybe to use another library to achieve this?
I used axios.head() request, which only returns the response header and not the data, but had to add to use:
axios options: decompress: false// default true
decompress indicates whether or not the response body should be
decompressed automatically. If set to true will also remove the
'content-encoding' header from the responses objects of all
decompressed responses

grcp request payload format

I'm trying to log in into a site which requires grcp content-type using requests. I alrady have a HTTP 2 client, but I don't know how body of my post request should look like.
When I'm trying to simply copy request as a curl from chrome network tab, request body looks like this:
%äEMAIL"PASSWORD(0
When I'm trying to request site with same body as I copied from chrome tab, I'mm getting response with this headers:
Grpc-Message: grpc: received message larger than max (218767392 vs. 4194304)
Grpc-Status: 8
I'm sure It's becouse wrong payload format
If anybody knows how can I pass data in request plase help.
If you're trying to send a one-off gRPC request, https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md would be helpful to know as to how to construct a message. Otherwise, using gRPC clients (https://github.com/grpc/grpc) would make more sense.

Twitter Search API: Getting error 32 could not authenticate you with specific searches but not every search

I'm using python3 to send a request to the Twitter Search API. I'm testing these requests in Postman, and then using the code snippit generator to copy and paste into my editor to run like so:
url = "https://api.twitter.com/1.1/search/tweets.json?q=twitter"
payload={}
headers = {
'Authorization': 'OAuth oauth_consumer_key="",oauth_token="",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1613517432",oauth_nonce="x",oauth_version="1.0",oauth_body_hash="",oauth_signature=""',
'Cookie': 'personalization_id=""; lang=en; guest_id='
}
twitter_response = requests.request("GET", url, headers=headers, data=payload)
The requests work just fine in Postman. But in my script, the request only works when the query parameter for the URL is "nasa". If I change it to anything else, I get error 32 Could not authenticate.
Is there some quirk about Python I don't know about when it comes to the Twitter Search API? Any guidance would be helpful here.
Sounds like you’re copying and pasting the OAuth headers from the Twitter Dev docs instead of calculating them with every new query. I think the docs use NASA as an example search query.
I was able to find a way around this by using the Tweepy API wrapper, which solved my OAuth issues. The headers weren't getting formatted properly for the request.

API get request not returning correct data in python

I am trying to get data from Uni Stats API by sending a get request. Following is my code:
import requests
dt = requests.get(url='https://API_TOKEN#data.unistats.ac.uk/api/v4/KIS/Institution/10007856.json')
print(dt)
Whenever I run this code it returns me <401 Response> but If I try the same url https://API_TOKEN#data.unistats.ac.uk/api/v4/KIS/Institution/10007856.json in the Postman software it returns correct data in json format.
So I wanted to know how can I send a get request with requests which can return correct data?
requests.get('https://data.unistats.ac.uk/api/v4/KIS/Institution/10007856.json', auth=('user', 'pass'))
401 is an authorization error, provide authorisation to the request.get method.
Depending on your user agent, you may be able to include the access token in the url as in the following examples:
https://accesstoken#data.unistats.ac.uk/api/v4/KIS/Institution/{ukprn}/Course/{kisCourseId}
Emphasis added.

Fetch post data after a request in NodeJS

i' m a bit new to Node, so question may be stupid...
I am sending a POST request to a website (through http.request) and I want to be able to use the invisible POST data I get along the response.
I hope this is achievable, and I think so since I am able to preview those data in Chrome debugger.
PS : I understand that we can use BodyParser to parse and get those while listening for a POST call server side, but I have found no example of how to use it coupled with an http.request.
Thanks !
If the body of the HTTP response contains JSON, then you need to parse it first in order to turn it from a string into a JavaScript object, like this:
var obj = JSON.parse(body);
console.log(obj.response.auth_token);
More info on various ways of sending a POST request to a server can be found here: How to make an HTTP POST request in node.js?
Edit : So we figured it out in the comments. The value I needed was in the form to begin with, as a hidden field. My error was to think it was generated afterward. So I'll just grab it first then login, so I can use it again for future POST requests on the website.

Resources