Require “open-url” load error when executing Nokogiri tester

拥有回忆 提交于 2019-12-12 02:58:36

问题


I am trying to follow the RailsCast to use Nokogiri.

Just a few very basic lines in my testing script file:

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

But when I execute it, I run into an error:

/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>'

I did install open url gem following this instruction:https://github.com/openurl/openurl How do I fix the error message?


回答1:


Just a typo. Use open-uri (not open-url).



来源:https://stackoverflow.com/questions/30488169/require-open-url-load-error-when-executing-nokogiri-tester

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!