Ruby:Phantom.js在特定网站上被阻止?

我正在使用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?

我试图将我的所有标题设置为查看我的Google Chrome的请求,但这似乎也没有解决.有没有人有什么建议?

解决方法

问题与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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...