Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode Requests Body in SeleniumBase #3486

Closed
ntdgo opened this issue Feb 7, 2025 · 2 comments
Closed

Decode Requests Body in SeleniumBase #3486

ntdgo opened this issue Feb 7, 2025 · 2 comments
Labels
external Outside SeleniumBase's scope. / Ask somewhere else. question Someone is looking for answers

Comments

@ntdgo
Copy link

ntdgo commented Feb 7, 2025

I am trying to retrieve and decode the response body of requests using SeleniumBase. Below is the code I am using:

from seleniumbase import Driver

driver = Driver(wire=True)
driver.get("https://seleniumbase.io/demo_page")
for request in driver.requests:
    body_bytes = request.response.body
    str_body = body_bytes.decode("utf-8")
    print(request.url)
    print(str_body)
driver.quit()

Problem:

  • I want to extract the response body in a readable JSON or string format.
  • The above implementation retrieves the body but may not be in a structured format.

Expected Behavior:

  • The response body should be in a structured JSON or string format for easy processing.

How can I properly decode and parse the response body in JSON or as a readable string?
Thank you for your support!!

@mdmintz mdmintz added question Someone is looking for answers external Outside SeleniumBase's scope. / Ask somewhere else. labels Feb 7, 2025
@mdmintz
Copy link
Member

mdmintz commented Feb 7, 2025

This is more of a selenium-wire and Python question than a SeleniumBase one.

The major info about the selenium-wire integration in SeleniumBase can be found here: #2145

@mdmintz mdmintz closed this as completed Feb 7, 2025
@mdmintz
Copy link
Member

mdmintz commented Feb 7, 2025

For fancier printing, you can also use pprint:

from rich.pretty import pprint

pprint("<h1>hello</h1>")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Outside SeleniumBase's scope. / Ask somewhere else. question Someone is looking for answers
Projects
None yet
Development

No branches or pull requests

2 participants