2

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:

  1. Return the new window in any way with the click() function.
  2. Switch the focus to the new window in JS.
  3. 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!

gluthier
  • 21
  • 5
  • Have you seen http://phantomjs.org/api/webpage/handler/on-page-created.html? Example: http://stackoverflow.com/a/25854614 – Artjom B. Oct 06 '15 at 10:06
  • Thanks, it didn't quite work as I wanted because the popup doesn't seem to load, but I found a workaround: the url of the popup appears in the callback `onResourceRequested`, so I'll parse it and then open the new page. – gluthier Oct 09 '15 at 13:15

0 Answers0