【问题标题】:Nokogiri not working in block : uninitialized constant ::Nokogiri?Nokogiri 不能在块中工作:未初始化的常量 ::Nokogiri?
【发布时间】:2014-01-05 17:02:59
【问题描述】:

我成功安装了 Ruby 1.9.1 和 Nokogiri,但是,当我尝试使用 Nokogiri 时出现以下错误:

uninitialized constant ::Nokogiri

这似乎是因为找不到 Nokogiri 宝石。这是我的代码:

File::open("test.html"){|file|
  puts file.class  => file 
  page = Nikogiri::HTML(file) => uninitialized constant ::Nokogiri
  puts page.class  
}

但这有效:

page = Nokogiri::HTML(open("test.html"))
file = open("test.html")  => file
page = Nokogiri::HTML(file) 
puts page.class  => document

那么你能帮我找出问题所在吗?

【问题讨论】:

    标签: ruby nokogiri


    【解决方案1】:

    代码有错别字:

    page = Nikogiri::HTML(file) # => uninitialized constant ::Nokogiri
    #       ^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      • 2014-05-13
      相关资源
      最近更新 更多