【问题标题】:PhantomJS failing to open HTTPS sitePhantomJS 无法打开 HTTPS 站点
【发布时间】:2012-08-14 20:00:56
【问题描述】:

我正在使用以下基于 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,发现它太好了,即使我没有继续解决这个问题。

【问题讨论】:

    标签: https screen-scraping phantomjs


    【解决方案1】:

    在您尝试运行 phantomjs 以连接到远程服务器的机器上,运行“openssl ciphers”。将列出的密码复制并粘贴到 --ssl-ciphers="" 命令行选项中。这会告诉连接的 Web 服务器哪些密码可用于与您的客户端通信。如果您没有在自己的机器上设置可用的密码,它可以使用您的机器不理解的任何密码,默认现代浏览器会使用默认设置。

    【讨论】:

      【解决方案2】:

      我收到了

      从 phantomJS(在 CentOS 6.6 上运行)创建 SSL 上下文时出错

      从源代码构建为我修复了它。不要忘记使用您构建的 phantomjs。 (而不是 /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>
      

      【讨论】:

      • 我不知道为什么人们对您的回答给予负面评价。在尝试了上述所有解决方案之后,经过几天的努力,这是唯一对我有用的解决方案。 phantomJS 因为 qt 编译起来挺烦的,不过还是值得的。
      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

        phantomjs --ssl-protocol=any test.js
        

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

        【讨论】:

        • 我不得不使用这 3 个参数并且它解决了:“--web-security=false”、“--ssl-protocol=any”、“--ignore-ssl-errors=true” . webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', "--web-security=false", "--ssl-protocol=any"])
        【解决方案5】:

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

        升级到 phantomJS 2.1.1 修复了它。

        我使用https://gist.github.com/julionc/7476620的phantomJS安装说明,将phantomJS版本改为2.1.1。

        【讨论】:

          【解决方案6】:

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

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

          我发现 PhantomJS 正在使用“Keep-Alive”(大写),并且连接没有保持活动状态。 :)

          【讨论】:

            【解决方案7】:

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

            【讨论】:

            • 这个技巧解决了我在 codeship CI 上的问题,运行 phantomjs + behat 套件(经过大约 10 个小时的调试和尝试)
            • 是的。经过几个愚蠢的时间后,你的评论让我很开心!
            • 修复了我的问题!!!
            【解决方案8】:

            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,因为它与验证我的环回网络服务器的自签名证书无关。

            【讨论】:

              【解决方案9】:

              问题很可能是由于 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。我希望这会有所帮助。

              【讨论】:

              • 谢谢,这也解决了我的问题。我的情况是,我在浏览器上没有收到 Cert 错误,所以这很令人困惑,但我确实 curl 详细并注意到一个不起作用的是使用 Wildcard Cert(即:CN=*.example.com)。如果 phantomjs 可以返回详细的失败原因,那就太好了。
              • 圣猴。我希望 SSL 错误得到解释,只有堆栈溢出和粉红色的独角兽帮助我找到了根本原因。谢谢大家
              • 很高兴这对人们有所帮助。也许 PhantomJS 需要更新以使用另一个命令行参数提供详细的 SSL 错误。我知道 Qt 中提供了 SSL 错误信息,但大多数时候人们只是压制错误而不明确处理它们。
              • 我知道我玩游戏迟到了,但是我发现在脚本名称之后添加选项不起作用-您需要按顺序调用它:@ 987654323@
              • 是的,--ignore-ssl-errors=yes 选项应该出现在脚本名称之前。感谢您指出这一点。
              【解决方案10】:

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

              要解决这个问题,您应该能够运行 PhantomJS:

              phantomjs --ssl-protocol=tlsv1
              

              希望 PhantomJS 很快会更新,使 TLSv1 成为默认设置,而不是 SSLv3。

              【讨论】:

              • 1.9.8 版本将默认切换为 TLSv1:github.com/ariya/phantomjs/issues/12670
              • 帮我修好了,服务器上禁用了 SSLv3
              • 请注意,更新到 PhantomJS 1.9.8 会导致 new bug
              • 这应该是公认的答案。在我看来,禁用 SSL 或允许任何协议都不是好的解决方案。感谢分享。
              • 如何从 SSL 握手问题中获得更详细的调试?
              【解决方案11】:

              如果有人将 Phantomjs 与 Sahi 一起使用,--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>
              

              【讨论】:

                【解决方案12】:

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

                【讨论】:

                • 将 ssl-protocols 更改为 tlsv1 也对我有用,谢谢!
                • +1 解决了我的问题,幸运的是你不在我身边,因为我现在会吻你哈哈,干杯
                • 这正是我所需要的。非常感谢!我使用“any”而不是 tlsv1,这也可以。 (如果我访问其他 ssl 网站,似乎更安全。
                • 把用户代理改成什么?
                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 2014-12-23
                • 1970-01-01
                • 1970-01-01
                • 2017-11-17
                相关资源
                最近更新 更多