Ruby:Phantom.js在特定网站上被阻止?
发布时间:2020-12-16 22:03:22 所属栏目:百科 来源:网络整理
导读:我正在使用capybara poltergeist来自动化tumblr.com上的一个小脚本 我的脚本与我的chrome驱动程序正常工作.我的poltergeist驱动程序加载所有其他网站只是罚款,但由于某些原因抛出了一个Capybara :: Poltergeist :: StatusFailError当我尝试加载tumblr. 复制
|
我正在使用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/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
