I'm using PhantomJS to retrieve the source code of a website after some AJAX manipulations of the DOM. Then using jQuery, I'm simulating a click on a button element (which has it's link hidden in an obscure JavaScript script). This button's onClick
effect is to open a new window.
What I'd like to do is retrieve the source code of this new window.
What I cannot do is use the window.open("url")
method in JS because I cannot retrieve the url of the new window since it's obfuscated in a script.
Some workaround I've been looking at but haven't succeeded to implement:
- Return the new window in any way with the
click()
function. - Switch the focus to the new window in JS.
- Retrieve the url of the button's
onClick
whitout having to parse the JS script.
Here's what I've got at the moment:
var page = require("webpage").create();
page.open("http://www.example.com", function() {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
var page = page.evaluate(function() {
$("#myButton").click(function() {
// ???
});
});
phantom.exit();
});
});
I'm open to other frameworks/technologies if there is a solution!