In CasperJS, I am working with a site that has a button like this:
<a id="showBills"
onclick="javascript:{showBills(); return false;}"
href="#">Show Bills</a>
Clicking it generates an XMLHttpRequest POST message with a massive form full of magic numbers and state. The server responds by sending a JSON data structure that I want to capture.
In this case, I can't simply call casper.getPageContent()
to get the JSON data, since it's interpreted by the client and incorporated into the DOM.
Nor can I call casper.download(...)
since I can't manually reconstruct the form data required for the POST request.
the question
How can I 'intercept' the JSON data sent in response to an onClick()-backed click?
half an idea
There may be some way to subvert the showBills() method on the client, for example to send the JSON response as an ordinary page (rather than an XMLHttpRequest). But that's just beyond my understanding of CasperJS, PhantomJS and HTTP protocols.