PhantomJS Loading HTTPS Page Errors
PhantomJS/CasperJS encounter difficulties opening certain web pages, including https://maizepages.umich.edu. When CasperJS attempts to load this page, it returns the error "PhantomJS failed to open page status=fail."
Determing the Cause
To identify the underlying cause, it's helpful to inspect the error logs. One common issue is the lack of support for TLSv1. PhantomJS versions prior to 1.9.8 use SSLv3 by default, which has been disabled on many websites due to the POODLE vulnerability.
Solution: TLSv1 Support
To address this issue, specify TLSv1 as the SSL protocol using the following command:
<code class="sh">casperjs --ssl-protocol=tlsv1 yourScript.js</code>
Alternately, the "any" protocol can be used, which will support any newer SSL protocols available in future PhantomJS versions. However, this may expose vulnerabilities on sites that haven't disabled SSLv3 yet.
<code class="sh">casperjs --ssl-protocol=any yourScript.js</code>
Verifying the Fix
To confirm whether the error is related to SSLv3, add the following resource error handler to your script:
<code class="sh">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); });</code>
If the error is indeed SSLv3-related, the error message will resemble:
Error code: 6. Description: SSL handshake failed
Additional Option
For certificate-related errors, it's recommended to use the --ignore-ssl-errors=true command-line option. This will ignore SSL certificate verification errors.
The above is the detailed content of Why does PhantomJS fail to open HTTPS pages and how can I fix it?. For more information, please follow other related articles on the PHP Chinese website!