首先,我是关于 Ruby的新手,我正在遵循 https://www.distilled.net/resources/web-scraping-with-ruby-and-nokogiri-for-beginners/的简单教程 我有一个test.rb文件,其中包含以下内容: require 'rubygems'require 'Nokogir
我有一个test.rb文件,其中包含以下内容:
require 'rubygems' require 'Nokogiri' require 'HTTParty' require 'Pry' require 'csv' # this is how we request the page we're going to scrape page = HTTParty.get('https://newyork.craigslist.org/search/pet?s=0') Pry.start(binding)
当我尝试运行ruby测试脚本时,我收到以下错误:
pjw@ubuntu:~/ruby/test$ruby test.rb /home/pjw/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- HTTParty (LoadError) from /home/pjw/.rvm/rubies/ruby-2.3.0/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from test.rb:1:in `<main>'
我已通过运行验证HTTParty正常工作:
httparty "https://newyork.craigslist.org/search/pet?s=0"
问题似乎是require语句.如果我混合订单或所需的宝石,第一个给出与上面相同的错误.我在网上搜索过,似乎找不到我错过的东西……
> in `require’: cannot load such file — httparty (LoadError) – (无答案)
> kernel_require.rb:55:in `require’: cannot load such file error – (bundle exec ruby test.rb“找不到Gemfile或.bundle /目录”)
> Unable to run .rb files on mac – getting /.rbenv/versions/2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require’ – (已安装GEMS)
pjw@ubuntu:~/ruby/test$lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS Release: 16.04 Codename: xenial pjw@ubuntu:~/ruby/test$ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux] pjw@ubuntu:~/ruby/test$gem list *** LOCAL GEMS *** actioncable (5.0.0.1) actionmailer (5.0.0.1) actionpack (5.0.0.1) actionview (5.0.0.1) activejob (5.0.0.1) activemodel (5.0.0.1) activerecord (5.0.0.1) activesupport (5.0.0.1) addressable (2.5.0) arel (7.1.4) autoprefixer-rails (6.5.3, 6.5.2, 6.5.1) bcrypt (3.1.11) bigdecimal (default: 1.2.8) bootstrap (4.0.0.alpha5) bootstrap-datepicker-rails (1.6.4.1) bootstrap-sass (3.3.7) builder (3.2.2) bundler (1.13.6) bundler-unload (1.0.2) byebug (9.0.6) cancancan (1.15.0) coderay (1.1.1) coffee-rails (4.2.1) coffee-script (2.4.1) coffee-script-source (1.10.0) commonjs (0.2.7) concurrent-ruby (1.0.2) connection_pool (2.2.1, 2.2.0) dashing-rails (2.5.0) debug_inspector (0.0.2) devise (4.2.0) did_you_mean (1.0.2, 1.0.0) erubis (2.7.0) execjs (2.7.0) executable-hooks (1.3.2) ffi (1.9.14) figaro (1.1.1) gem-wrappers (1.2.7) geocoder (1.4.0) globalid (0.3.7) gravatarify (3.1.1) httparty (0.14.0) i18n (0.7.0) io-console (0.4.6, default: 0.4.5) jbuilder (2.6.0) jquery-rails (4.2.1) json (2.0.2, default: 1.8.3) less (2.6.0) less-rails (2.8.0) listen (3.1.5, 3.0.8) loofah (2.0.3) mail (2.6.4) method_source (0.8.2) mime-types (3.1) mime-types-data (3.2016.0521) mini_portile2 (2.1.0) minitest (5.9.1, 5.8.3) multi_json (1.12.1) multi_xml (0.5.5) net-telnet (0.1.1) nio4r (1.2.1) nokogiri (1.6.8.1) orm_adapter (0.5.0) power_assert (0.3.1, 0.2.6) pry (0.10.4) psych (2.1.1, default: 2.0.17) public_activity (1.5.0) public_suffix (2.0.4) puma (3.6.0) rack (2.0.1) rack-test (0.6.3) rails (5.0.0.1) rails-dom-testing (2.0.1) rails-html-sanitizer (1.0.3) rails_serve_static_assets (0.0.5) rails_stdout_logging (0.0.5) railties (5.0.0.1) rake (11.3.0, 10.4.2) rb-fsevent (0.9.8) rb-inotify (0.9.7) rdoc (5.0.0, default: 4.2.1) redis (3.3.1) responders (2.3.0) ruby_dep (1.5.0) rubygems-bundler (1.4.4) rubygems-update (2.6.8) rufus-scheduler (3.2.2) rvm (1.11.3.9) sass (3.4.22) sass-rails (5.0.6) simple_calendar (2.2.0) simple_form (3.3.1) slop (4.4.1, 3.6.0) spring (2.0.0) spring-watcher-listen (2.0.1) sprockets (3.7.0) sprockets-rails (3.2.0) sqlite3 (1.3.12) table_print (1.5.6) test-unit (3.2.2, 3.1.5) thor (0.19.1) thread_safe (0.3.5) tilt (2.0.5) turbolinks (5.0.1) turbolinks-source (5.0.0) twitter-bootstrap-rails (3.2.2) tzinfo (1.2.2) uglifier (3.0.3, 3.0.2) warden (1.2.6) web-console (3.4.0, 3.3.1) websocket-driver (0.6.4) websocket-extensions (0.1.2) wunderground (1.2.0)试试这个.这完全是个小问题
require 'httparty'