我需要从动态构建的页面获取数据,我找到的一个解决方案是 Watir。
irb 的下一个代码可以正常工作:
require 'rubygems'
require 'watir-webdriver'
require 'headless'
Headless.ly do
browser = Watir::Browser.new :firefox
browser.goto "google.com"
browser.close
end
如果我尝试从 Rails 应用程序运行它有下一个问题:
宝石文件:
gem 'headless'
gem 'watir-webdriver'
行动:
def test_action
Headless.ly do
browser = Watir::Browser.new(:firefox)
browser.goto "google.com"
browser.close
end
end
有下一个输出:
no such file to load -- {
"frozen": {
"app.update.auto": false,
"app.update.enabled": false,
"browser.download.manager.showWhenStarting": false,
"browser.EULA.override": true,
"browser.EULA.3.accepted": true,
"browser.link.open_external": 2,
"browser.link.open_newwindow": 2,
"browser.offline": false,
"browser.safebrowsing.enabled": false,
"browser.safebrowsing.malware.enabled": false,
"browser.search.update": false,
"browser.sessionstore.resume_from_crash": false,
"browser.shell.checkDefaultBrowser": false,
"browser.tabs.warnOnClose": false,
"browser.tabs.warnOnOpen": false,
"devtools.errorconsole.enabled": true,
"dom.disable_open_during_load": false,
"extensions.autoDisableScopes": 10,
"extensions.logging.enabled": true,
"extensions.update.enabled": false,
"extensions.update.notifyUser": false,
"network.manage-offline-status": false,
"network.http.phishy-userpass-length": 255,
"offline-apps.allow_by_default": true,
"prompts.tab_modal.enabled": false,
"security.fileuri.origin_policy": 3,
"security.fileuri.strict_origin_policy": false,
"security.warn_entering_secure": false,
"security.warn_entering_secure.show_once": false,
"security.warn_entering_weak": false,
"security.warn_entering_weak.show_once": false,
"security.warn_leaving_secure": false,
"security.warn_leaving_secure.show_once": false,
"security.warn_submit_insecure": false,
"security.warn_viewing_mixed": false,
"security.warn_viewing_mixed.show_once": false,
"signon.rememberSignons": false,
"toolkit.networkmanager.disable": true,
"toolkit.telemetry.prompted": 2,
"toolkit.telemetry.enabled": false,
"toolkit.telemetry.rejected": true
},
"mutable": {
"browser.dom.window.dump.enabled": true,
"browser.startup.page": 0,
"browser.startup.homepage": "about:blank",
"dom.max_script_run_time": 30,
"dom.report_all_js_exceptions": true,
"javascript.options.showInConsole": true,
"network.http.max-connections-per-server": 10,
"webdriver_accept_untrusted_certs": true,
"webdriver_assume_untrusted_issuer": true
}
}
问题在哪里?