1

I am trying to load a web page and monitor it for XHR (XMLHttpRequests). To do this I am using Ghost.py with Python2.7. I can see the XHR being made and can read the URL and response, however I would like to read the request body so that I can recreate these requests at a later date.

from ghost import Ghost, Session

ghost = Ghost()

with ghost.start():
    session = Session(ghost, download_images=False, display=False)
    page, rs = session.open("https://www.example.com/", timeout=60)
    assert page.http_status == 200

    result, resources = session.wait_while_selector('[class=loading]:not([style="display: none;"])', timeout=60)
    for resource in resources:
        print resource.url
        print resource.content

I have searched within the documentation, but cannot find any references to XHR request body and I have searched within the returned resources object for references to the request, but can only find request.headers (which does not include the POST body) and the _reply data.

Can you save the POST body of a XHR request as well as the response?

0 Answers0