【问题标题】:Require "open-url" load error when executing Nokogiri tester执行 Nokogiri 测试器时需要“open-url”加载错误
【发布时间】:2015-05-27 16:27:12
【问题描述】:

我正在尝试按照 RailsCast 使用 Nokogiri。

我的测试脚本文件中只有几行非常基本的行:

require 'rubygems'
require 'nokogiri'
require 'open-url'

url = "http://www.walmart.com/search/search-ng.do?search_constraint=0&ic=48_0&search_query=Batman&Find.x=0&Find.y=0&Find=Find"
doc = Nokogiri::HTML(open(url))
puts doc.at_css("title").text

但是当我执行它时,我遇到了一个错误:

/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- open-url (LoadError)
    from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
    from nokogiri.test.rb:3:in `<main>'

我确实按照以下说明安装了 open url gem:https://github.com/openurl/openurl 如何修复错误消息?

【问题讨论】:

  • Ruby 的OpenURI 是内置的,可能是您想要使用的。请改用require 'open-uri'

标签: ruby-on-rails ruby ruby-on-rails-3 gem bundle


【解决方案1】:

只是一个错字。使用open-uri(不是open-url)。

【讨论】:

    猜你喜欢
    • 2011-12-06
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多