Casperjs脚本在OSX上运行,但不在Windows上运行

时间:2015-01-02 20:38:55

标签: ssl phantomjs casperjs

Phantomjs版本 - 1.9.7 Casperjs版本 - 1.1.0-beta3

这是代码

var casper = require('casper').create({
    verbose: true,
    logLevel: 'debug',

});

casper.start('https://www.gmail.com', function() {
    casper.wait(3000, function()  {
        this.capture('gmail.png');
    });
});

casper.run(function() {
    this.exit();
});

Windows上的日志显示

casperjs --ssl-protocol=any --ignore-ssl-errors=true login.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://www.gmail.com/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.gmail.com/, type=Other, willNavigate=true, isMainFrame=true
[warning] [phantom] Loading resource failed with status=fail: https://www.gmail.com/
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2: done in 349ms.
[info] [phantom] Step _step 3/3: done in 371ms.
[info] [phantom] wait() finished waiting for 3000ms.
[debug] [phantom] Capturing page to C:/Users/username/Desktop/gmail.png
[info] [phantom] Capture saved to C:/Users/username/Desktop/gmail.png
[info] [phantom] Done 3 steps in 3408ms

在OSX上,它显示以下内容

[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://www.gmail.com/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.gmail.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://mail.google.com/mail/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1"
[debug] [phantom] Navigation requested: url=https://accounts.youtube.com/accounts/CheckConnection?pmpo=https://accounts.google.com&v=-320444755&timestamp=1420230909413, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2 https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1 (HTTP 200)
[info] [phantom] Step anonymous 2/2: done in 1398ms.
[info] [phantom] Step _step 3/3 https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1 (HTTP 200)
[info] [phantom] Step _step 3/3: done in 1418ms.
[info] [phantom] wait() finished waiting for 3000ms.
[debug] [phantom] Capturing page to /Users/username/code/casperjs/gmail.png
[info] [phantom] Capture saved to /Users/username/code/casperjs/gmail.png
[info] [phantom] Done 3 steps in 4511ms

两个平台上的代码都是一样的,我尝试了各种组合--ignore-ssl-errors等没有运气。有什么建议?

根据Artjom B.的建议,我更新了这样的代码 -

var webPage = require('webpage');
var page = webPage.create();

var casper = require('casper').create({
    verbose: true,
    logLevel: 'debug',
    pageSettings: {
         userAgent: 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1'
    }
});

casper.on('resource.error', function(resource) {
    this.echo('Error: ' +msg, 'ERROR'); });

casper.on("page.error", function(msg, trace) {
    this.echo("Error: " + msg, "ERROR");
});

page.onResourceTimeout = function(request) {
    console.log('Response (#' + request.id + '): ' + JSON.stringify(request));
};

casper.on("remote.message", function(msg, trace) {
    this.echo("Error: " + msg, "ERROR");
});

casper.start('https://www.gmail.com', function() {
    casper.wait(3000, function()  {
        this.capture('gmail.png');
    });
});

casper.run(function() {
    this.exit();
});

这给出了相同的结果 -

C:\Users\username\Desktop>casperjs --ssl-protocol=any --ignore-ssl-errors=true pt-login.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://www.gmail.com/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.gmail.com/, type=Other, willNavigate=true, isMainFrame=true
[warning] [phantom] Loading resource failed with status=fail: https://www.gmail.com/
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2: done in 338ms.
[info] [phantom] Step _step 3/3: done in 361ms.
[info] [phantom] wait() finished waiting for 3000ms.
[debug] [phantom] Capturing page to C:/Users/username/Desktop/gmail.png
[info] [phantom] Capture saved to C:/Users/username/Desktop/gmail.png
[info] [phantom] Done 3 steps in 3462ms

0 个答案:

没有答案