ansvver
ansvver

Reputation: 317

Casperjs did not render page completely

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!

Upvotes: 0

Views: 751

Answers (1)

Giacomo Pigani
Giacomo Pigani

Reputation: 2306

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

Upvotes: 3

Related Questions