我正在使用capybara poltergeist来自动化tumblr.com上的一个小脚本
我的脚本与我的chrome驱动程序正常工作.我的poltergeist驱动程序加载所有其他网站只是罚款,但由于某些原因抛出了一个Capybara :: Poltergeist :: StatusFailError当我尝试加载tumblr.
复制步骤:
$brew install phantomjs $gem install capybara $gem install poltergeist $gem install selenium-webdriver $irb require 'capybara/poltergeist' module Drivers class Poltergeist < Capybara::Poltergeist::Driver def needs_server? false end end end Capybara.register_driver :poltergeist_errorless do |app| Drivers::Poltergeist.new(app,js_errors: false,timeout: 10000,phantomjs_options: ['--load-images=no','--ignore-ssl-errors=yes']) end session = Capybara::Session.new(:poltergeist_errorless) session.visit('https://google.com') # This works fine session.visit('https://tumblr.com') # This does not work?
解决方法
问题与phantomjs SSL握手失败有关.你可以拿我的
gist并运行phantomjs,你会看到:
[cut] = onResourceError() - unable to load url: "https://www.tumblr.com/" - error code: 6,description: SSL handshake Failed = onResourceReceived() id: 3,stage: "end",response: {"contentType":null,"headers":[],"id":3,"redirectURL":null,"stage":"end","status":null,"statusText":null,"time":"2014-09-16T12:06:05.547Z","url":"https://www.tumblr.com/"} = onLoadFinished() status: fail DONE WITH fail WebPage(name = "WebPage")
检查一个解决方法是使用–ssl-protocol = any在幻像中,所以你的代码将成为:
Capybara.register_driver :poltergeist_errorless do |app| Drivers::Poltergeist.new(app,'--ignore-ssl-errors=yes','--ssl-protocol=any']) end
上班.
参考文献:
> [debug phantom js page]:http://newspaint.wordpress.com/2013/04/25/getting-to-the-bottom-of-why-a-phantomjs-page-load-fails/
> [ssl-protocol-any]:https://stackoverflow.com/a/24679134/258267