1

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 a description etc.

The link for each photo is as follows:

<a href="javascript:void(0)" data="10019"  class="seeMore"></a>

First I want to start with the basics, of just extracting the description etc. from one single person. So I want to execute the JavaScript above to write the popup window, and when I'm on the popup window I can then extract the content of the div's on the popup.

I've looked at PhantomJS and I really don't know where to start. I've used Cheerio to get some simple information from the page, and I want to move on to executing the popup window through JS and then extracting data from that.

Any help would be appreciated as I'm a bit of a newbie to screen scraping in general.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
germainelol
  • 3,231
  • 15
  • 46
  • 82

1 Answers1

0

You can do this analogous to how CasperJS does it.

page.open(yourUrl, function(success){
    // mainPage is loaded, so every next page could be a popup
    page.onPageCreated = function onPageCreated(popupPage) {
        popupPage.onLoadFinished = function onLoadFinished() {
            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.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222