javascript 从 casperjs 使用 --ignore-ssl-errors=true 运行 phantomjs

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20243033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:04:38  来源:igfitidea点击:

Run phantomjs with --ignore-ssl-errors=true from casperjs

javascriptsslphantomjscasperjs

提问by Piotr Wójcik

I have a problem with https page. Page is completly ok, it exist but phantomjs tell me something else: 'loading resource failed with status fail'. I read about it for a while and for now i know it's phantomjs bug and the solution to this problem is:

我的 https 页面有问题。页面完全没问题,它存在,但 phantomjs 告诉我其他事情:“加载资源失败,状态失败”。我读了一段时间,现在我知道它是 phantomjs 错误,这个问题的解决方案是:

--ignore-ssl-errors=true

So I know solution, but don't how to use it. How can I pass this to phantomjs from casper? Where should I do that ?

所以我知道解决方案,但不知道如何使用它。我怎样才能把它从 casper 传递给 phantomjs?我应该在哪里做?

EDIT:

编辑:

Entire code:

完整代码:

var casper = require('casper').create({
        verbose: true,
        logLevel: 'warning',
        pageSettings: { javascriptEnabled:  true },
        viewportSize: {width: 1024, height: 768}
    });

    var url = 'http://us3.php.net/manual/en/function.explode.php',
        xp = require('casper').selectXPath;

    // ### AKCJE PODSTAWOWE ###
        casper.start(url);

            casper.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0');

            casper.then(function(){this.captureSelector('logi/img1.png', 'body');});

            casper.then(function(){ this.sendKeys(xp('/html/body/nav/div/div/div/form/span/input[2]'),'test18');});

            casper.then(function(){this.captureSelector('logi/img2.png', 'body');})

            casper.thenClick(xp('/html/body/div[3]/div/section/div/div[2]/a[1]'));

            casper.wait(2000);
            casper.then(function(){this.captureSelector('logi/img3.png', 'body');})

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

采纳答案by sudipto

As per https://casperjs.readthedocs.org/en/latest/cli.html#casperjs-native-options

根据https://casperjs.readthedocs.org/en/latest/cli.html#casperjs-native-options

Last but not least, you can still use all PhantomJS standard CLI options as you would do with any other phantomjs script:

$ casperjs --web-security=no --cookies-file=/tmp/mycookies.txt myscript.js

最后但同样重要的是,您仍然可以像使用任何其他 phantomjs 脚本一样使用所有 PhantomJS 标准 CLI 选项:

$ casperjs --web-security=no --cookies-file=/tmp/mycookies.txt myscript.js

So, I guess, it would be

所以,我想,这将是

casperjs --ignore-ssl-errors=true yourjsapp.js 

回答by james

Was having the same issue with a site that was previously working but then suddenly stopped working with the "Loading resource failed with status=fail:" message.

以前可以正常工作但突然停止工作的站点也遇到了同样的问题,并显示“加载资源失败,状态 = 失败:”消息。

I hadn't changed versions of anything nor my script so something must have changed on the server side. Ultimately, the fix for me was to set the following option:

我没有改变任何东西的版本,也没有改变我的脚本,所以一定是服务器端发生了一些变化。最终,我的解决方法是设置以下选项:

--ssl-protocol=tlsv1

This link was useful in giving some different options to try: https://github.com/n1k0/casperjs/issues/49

此链接有助于提供一些不同的尝试选项:https: //github.com/n1k0/casperjs/issues/49

Other suggestions on the page were:

页面上的其他建议是:

--ignore-ssl-errors=true
--ssl-protocol=any