Watir-Webdriver,PhantomJS和重定向到https的URL

时间:2014-10-27 08:18:10

标签: ruby ssl phantomjs watir-webdriver

我在使用PhantomJS和Watir-Webdriver时遇到了麻烦。我有“http”方案的URL,返回HTTP 301永久移动并重定向到新的“https”位置。两个例子:

  1. http://make.crowdflower.com
  2. http://click.alfabank.ru
  3. 我写了一个剧本:

    require 'watir-webdriver'
    b = Watir::Browser.new :phantomjs, :args => ['--ignore-ssl-errors=true']
    b.goto 'http://make.crowdflower.com'
    puts b.title
    puts b.url
    b.close
    

    输出结果为:

    (empty line)
    about:blank
    

    版本是:Ruby 2.1.0,watir-webdriver 0.6.11,phantomjs 1.9.7。

    我想知道为什么会这样。任何建议都非常感谢。

1 个答案:

答案 0 :(得分:7)

原因很可能是POODLE漏洞迫使网站删除SSLv3支持。自PhantomJS< v1.9.8默认使用SSLv3,ssl握手失败,页面无法加载。您应该将ssl-protocol设置为tlsv1any

require 'watir-webdriver'
b = Watir::Browser.new :phantomjs, :args => ['--ssl-protocol=tlsv1']
b.goto 'http://make.crowdflower.com'
puts b.title
puts b.url
b.close

PhantomJS 1.9.8默认使用TLSv1。有关更多最新信息,请参阅this answer。请注意,bug in 1.9.8可能会影响功能。最好坚持1.9.7直到2.0出来。