0

I tried to visit the webpage and capture with casperjs, but nothing showed in .png and no final html DOMs generated.(Page works perfectly in chrome browser)

Code:

var casper = require('casper').create({
verbose: true,
logLevel: 'debug'
});
casper.start("http://m.weibo.cn/status/Er9b7wxsD", function() {
    this.wait(5000, function() {
        this.scrollTo(0, 0);
        this.echo(this.getHTML('html', true));
        this.capture('all.png');
    });

});
casper.run();

I'm using CasperJS version 1.1.2 and phantomjs version 2.1.1

Any idea is very much appreciated and thanks in advance!

ansvver
  • 317
  • 1
  • 12
  • Try to use error logging in CasperJS to check if tehre are errors: http://docs.casperjs.org/en/latest/logging.html – Vaviloff Mar 18 '17 at 11:00
  • If you paste the resulting html in a browser you'll see that casperjs is really showing you the correct thing in 'all.jpg'. I tried changing the userAgent and the window size but they are using another method to detect you aren't using a real browser – Giacomo Pigani Mar 20 '17 at 11:55
  • @GiacomoTecyaPigani :) Thanks for your comment. I've tried to change the core to Slimerjs and casperjs can render the website. I am not sure if that is the problem of Phantomjs or the detection of the website. :( – ansvver Mar 21 '17 at 02:09
  • @Vaviloff I have logged it, but nothing useful showed :( – ansvver Mar 21 '17 at 02:10

1 Answers1

3

Add this to the end of your script:

casper.on("page.initialized", function(page) {
    page.evaluate(function() {
        delete window.callPhantom;
        delete window._phantom;
    });
});

Basically the site is checking if you are using PhantomJS.

Since CasperJS runs on top of it (by default) you are seeing nothing

Giacomo Pigani
  • 2,256
  • 27
  • 36