Skip to content Skip to sidebar Skip to footer

Phantomjs Executing Javascript In A Popup For Data Extraction

So I have a web page with some photos of people. When you click on a photo of the person the JavaScript is executed and produces a popup with some more detailed information such as

Solution 1:

You can do this analogous to how CasperJSdoesit.

page.open(yourUrl, function(success){
    // mainPage is loaded, so every next page could be a popup
    page.onPageCreated = functiononPageCreated(popupPage) {
        popupPage.onLoadFinished = functiononLoadFinished() {
            popupPage.evaluate(function(){
                // do something in popup page context like extracting data
            });
        };
    };

    // click to trigger the popup
    page.evaluate(function(){
        document.querySelector("a.seeMore").click();
        // or something from here: http://stackoverflow.com/questions/15739263/phantomjs-click-an-element
    });
});

Do not forget to overwrite/nullify page.onPageCreated before navigating away from the main page.

Post a Comment for "Phantomjs Executing Javascript In A Popup For Data Extraction"