javascript CasperJS/PhantomJS 不加载 https 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26415188/
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
CasperJS/PhantomJS doesn't load https page
提问by Vishaal Kalwani
I know there are certain web pages PhantomJS/CasperJS can't open, and I was wondering if this one was one of them: https://maizepages.umich.edu. CasperJS gives an error: PhantomJS failed to open page status=fail.
我知道有些网页 PhantomJS/CasperJS 无法打开,我想知道这是否是其中之一:https://maizepages.umich.edu 。CasperJS 报错:PhantomJS failed to open page status=fail。
I tried ignoring-ssl-errors and changing my user agent but I'm not sure how to determine which ones to use.
我尝试忽略-ssl-errors 并更改我的用户代理,但我不确定如何确定要使用哪些。
All I'm doing right now is the basic casper setup with casper.start(url, function () { ... })
where url=https://maizepages.umich.edu
;
我现在正在做的就是使用casper.start(url, function () { ... })
where进行基本的 casper 设置url=https://maizepages.umich.edu
;
回答by Artjom B.
The problem may be related to the recent discovery of a SSLv3 vulnerability (POODLE). Website owners were forced to remove SSLv3 support from their websites. Since PhantomJS < v1.9.8 uses SSLv3 by default, you should use TLSv1:
该问题可能与最近发现的一个 SSLv3 漏洞(POODLE)有关。网站所有者被迫从他们的网站中删除 SSLv3 支持。由于 PhantomJS < v1.9.8默认使用 SSLv3 ,您应该使用 TLSv1:
casperjs --ssl-protocol=tlsv1 yourScript.js
The catchall solution would be to use any
for when newer PhantomJS versions come along with other SSL protocols. But this would make the POODLE vulnerability exploitable on sites which haven't yet disabled SSLv3.
any
当新的 PhantomJS 版本与其他 SSL 协议一起出现时,通用的解决方案将被使用。但这将使 POODLE 漏洞可在尚未禁用 SSLv3 的站点上被利用。
casperjs --ssl-protocol=any yourScript.js
Alternative method: Update to PhantomJS 1.9.8 or higher. Note that updating to PhantomJS 1.9.8 leads to a new bug, which is especially annoying for CasperJS.
替代方法:更新到 PhantomJS 1.9.8 或更高版本。请注意,更新到 PhantomJS 1.9.8 会导致一个新的 bug,这对 CasperJS 来说尤其令人讨厌。
How to verify:Add a resource.error
event handler like this at the beginning of your script:
如何验证:resource.error
在脚本的开头添加这样的事件处理程序:
casper.on("resource.error", function(resourceError){
console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
});
If it is indeed a problem with SSLv3 the error will be something like:
如果确实是 SSLv3 的问题,则错误将类似于:
Error code: 6. Description: SSL handshake failed
错误代码:6。说明:SSL 握手失败
As an aside, you also might want to run with the --ignore-ssl-errors=true
commandline option, when there is something wrong with the certificate.
--ignore-ssl-errors=true
顺便说一句,当证书有问题时,您可能还想使用命令行选项运行。