0

I need the following: If I send a GET Request like this:

page.open("<URL>",function (status) {
    // If connection wasn't successful:
    if (status !== 'success') {
         console.log('Unable to access network');
    } else {
         console.log(page.content)
    }
}

I get logged the page like when You right-click the page and click View Page Source.... I need it to be like when You open the developer tools inside Chrome and see the resulting page with all the javascript done. Is it possible?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
duri
  • 71
  • 2
  • 8
  • Welcome to Stack Overflow! If the linked duplicate doesn't work for you... Which PhantomJS version do you use? Please register to the `onConsoleMessage`, `onError`, `onResourceError`, `onResourceTimeout` events ([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf#file-1_phantomerrors-js)). Maybe there are errors. – Artjom B. Jul 24 '16 at 20:04

1 Answers1

0

There is an onLoadFinished handler which should give you the content after the page is completely loaded :

http://phantomjs.org/api/webpage/handler/on-load-finished.html

page.onLoadFinished = function(status) {
  console.log('Status: ' + status);
  if (status !== 'success') {
     console.log('Unable to access network');
  } else {
     console.log(page.content)
  }
};
mxlse
  • 2,654
  • 17
  • 31
  • It actually doesn't provide me what I want. On my page are many `
    `. If I parse the page's content in `onLoadFinished` to DOM (HTML) the length of the `html.getElementsByClassName("podSplashRow")` equals to 0
    – duri Jul 23 '16 at 16:02
  • In this case the UI elements are loaded after the page load has finished. You could try `var html = page.evaluate(function() { return document.documentElement.outerHTML; }); console.log(html);` – mxlse Jul 23 '16 at 16:25
  • It just doesn't give me the result I want. Many elements that I see in developer tools are missing in this code, it's like some javascript was not proceeded or what. – duri Jul 23 '16 at 17:09
  • The UI elements are probably created later during runtime. You would need to get the content after those events. Do you know the executed Code? – mxlse Jul 23 '16 at 17:13
  • Yes maybe there are some scripts running after some time, the `setTimeout` can do the job? I don't understand Your question, what do you mean by executed code? – duri Jul 23 '16 at 17:41
  • If you know the Javascript Codes which are executed on the page – mxlse Jul 23 '16 at 18:38
  • I am trying to parse data from this website: https://mobile.bet365.com/?apptype=&appversion=&cb=1469350249#type=Splash;key=1;ip=0;lng=26 , as you can see the page starts with loading circle and I can't get to element with class `podSplashRow`. How to actually do it?? – duri Jul 24 '16 at 09:46