PhantomJS无法打开HTTPS站点

时间:2012-08-18 19:21:54

标签: https screen-scraping phantomjs

我正在使用以下基于loadspeed.js示例的代码打开一个https://站点,该站点也需要http服务器身份验证。

var page = require('webpage').create(), system = require('system'), t, address;

page.settings.userName = 'myusername';
page.settings.password = 'mypassword';

if (system.args.length === 1) {
    console.log('Usage: scrape.js <some URL>');
    phantom.exit();
} else {
    t = Date.now();
    address = system.args[1];
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('FAIL to load the address');
        } else {
            t = Date.now() - t;
            console.log('Page title is ' + page.evaluate(function () {
                return document.title;
            }));
            console.log('Loading time ' + t + ' msec');
        }
        phantom.exit();
    });
}  

无法一直加载页面。这可能有什么问题?安全网站的处理方式是否有所不同?该网站可以通过浏览器成功访问。

我现在刚开始使用Phantom并发现即使我没有继续解决这个问题也不能停止玩游戏。

12 个答案:

答案 0 :(得分:151)

我尝试了Fred和Cameron Tinker的答案,但只有 - ssl-protocol = any 选项似乎可以帮助我:

phantomjs --ssl-protocol=any test.js

此外,我认为使用--ssl-protocol=any会更安全,因为您仍在使用加密,但--ignore-ssl-errors=true会忽略(duh)所有ssl错误,包括恶意错误。

答案 1 :(得分:121)

问题很可能是由于SSL证书错误造成的。如果您使用 - ignore-ssl-errors = yes 选项启动phantomjs,它应该继续加载页面,如果没有SSL错误那样:

phantomjs --ignore-ssl-errors=yes [phantomOptions] script.js [scriptOptions]

我看过一些网站在错误实施SSL证书方面遇到问题或者已经过期等等。有关phantomjs的完整命令行选项列表,请访问:http://phantomjs.org/api/command-line.html。我希望这会有所帮助。

答案 2 :(得分:71)

请注意,截至2014-10-16,PhantomJS默认使用SSLv3打开HTTPS连接。随着最近宣布的the POODLE vulnerability,许多服务器都禁用了SSLv3支持。

要解决这个问题,你应该可以用:

运行PhantomJS
phantomjs --ssl-protocol=tlsv1

希望PhantomJS能够尽快更新,使TLSv1成为默认值而不是SSLv3。

答案 3 :(得分:24)

遇到同样的问题......
--ignore-ssl-errors = yes还不足以解决它, 不得不做两件事:
1)更改用户代理
2)尝试了所有ssl协议,唯一有效的是tlsv1用于相关页面
希望这会有所帮助...

答案 4 :(得分:15)

我遇到了同样的问题(casperjs 1.1.0-beta3 / phantomjs 1.9.7)。使用--ignore-ssl-errors = yes和--ssl-protocol = tlsv1解决了它。只使用其中一个选项并没有为我解决。

答案 5 :(得分:1)

我正在接收

  

创建SSL上下文时出错&#34;来自phantomJS(在CentOS 6.6上运行)

从源码构建为我修复它。不要忘记使用你建造的幻影。 (如果你有的话,而不是/ usr / local / bin / phantomjs)

sudo yum -y install gcc gcc-c++ make flex bison gperf ruby openssl-devel freetype-devel fontconfig-devel libicu-devel sqlite-devel libpng-devel libjpeg-devel
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 2.0
./build.sh
cd bin/
./phantomjs <your JS file>

答案 6 :(得分:0)

如果有人在Sahi中使用Phantomjs,--ignore-ssl-errors选项需要进入你的browser_types.xml文件。它对我有用。

<browserType>
    <name>phantomjs</name>
    <displayName>PhantomJS</displayName>
    <icon>safari.png</icon>
    <path>/usr/local/Cellar/phantomjs/1.9.2/bin/phantomjs</path>
    <options>--ignore-ssl-errors=yes --debug=yes --proxy=localhost:9999 /usr/local/Cellar/phantomjs/phantom-sahi.js</options>
    <processName>"PhantomJS"</processName>
    <capacity>100</capacity>
    <force>true</force>
</browserType>

答案 7 :(得分:0)

shebang怎么样?

如果您使用shebang执行phantomjs脚本,请使用以下shebang行

#!/usr/bin/phantomjs --ignore-ssl-errors=yes

var system = require('system');
var webpage = require('webpage');

// ... rest of your script

使用上述任何答案。我个人喜欢--ignore-ssl-errors=yes,因为它与验证我的环回Web服务器的自签名证书无关。

答案 8 :(得分:0)

这里没有其他答案对我有帮助;可能是我正在使用的特定网站对其HTTP标头过于挑剔。这是有用的:

var page = webpage.create();
page.customHeaders = {
    "Connection": "keep-alive"
};

我发现PhantomJS正在使用&#34; Keep-Alive&#34; (大写),并没有保持联系。 :)

答案 9 :(得分:0)

我昨天得到了SSL Handshake Failed。我尝试了很多phantomJS选项组合(--ignore-ssl-errors=yes等),但都没有。

升级到phantomJS 2.1.1修复它。

我在https://redux.js.org/docs/faq/OrganizingState.html使用了phantomJS安装说明,将phantomJS版本更改为2.1.1。

答案 10 :(得分:0)

在您要运行phantomjs来连接到远程服务器的计算机上,运行“ openssl密码”。将列出的密码复制并粘贴到--ssl-ciphers =“”命令行选项中。这告诉正在连接的Web服务器可以使用哪些密码与您的客户端进行通信。如果您未在自己的计算机上设置可用的密码,则它可以使用您的计算机无法理解的默认默认现代浏览器所使用的任何密码。

答案 11 :(得分:-1)

唯一对我有用的是将phantomjs从1.9x升级到2.x;)