我正在尝试在Rails 4应用中截取页面。我尝试了几种方法,但最干净的似乎是使用水豚与恶作剧。
在我的Gemfile中,我有以下内容:
gem 'capybara'
gem 'capybara-screenshot'
gem 'poltergeist'
我的rake任务看起来像这样:
desc "Take a screenshot of top three articles"
task :screenshots => :environment do
require 'capybara'
require 'capybara/poltergeist'
include Capybara::DSL
Capybara.default_driver = :poltergeist
Capybara.run_server = false
articles = Article.order('score DESC').limit(3)
articles.each do |article|
visit(article.url)
screenshot_and_save_page
end
end
但是,这给了我这样的错误:
Unsafe JavaScript attempt to access frame with URL <someurl> from frame with URL http://static.ak.facebook.com/connect/xd_arbiter.php?version=40#channel=fcf48aa3c&origin=http%3A%2F%2Fwww.independent.co.uk. Domains, protocols and ports must match.
有任何线索如何解决这个问题?
答案 0 :(得分:0)
我想我通过添加以下内容解决了这个问题:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, :js_errors => false)
end