问题
I'm working on building a simple post miner using Ruby and the following tutorial (http://ngauthier.com/2014/06/scraping-the-web-with-ruby.html)
Here is my code I currently have:
#!/usr/bin/ruby
require 'capybara'
require 'capybara/poltergeist'
include Capybara::DSL
Capybara.default_driver = :poltergeist
visit "http://dilloncarter.com"
all(".posts .post ").each do |post|
title = post.find("h1 a").text
url = post.find("h1 a")["href"]
date = post.find("a")["datetime"]
summary = post.find("p.preview").text
puts title
puts url
puts date
puts summary
puts " "
end
and i'm getting errors loading the gemfiles like the following:
LoadError: cannot load such file -- capybara
from /Users/dilloncarter/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/dilloncarter/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from WP_Miner.rb:3
from /Users/dilloncarter/.rvm/rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>'
How can I get my gems to load properly?
回答1:
Have you installed capybara
and poltergeist
?
I just checked the tutorial you linked, and it doesn't seem to mention Gemfiles.
Also, if that is your script, you don't need a Gemfile.
All you need are the gems installed on your system and available in the ruby load path, and require
will find them.
Try in a terminal:
$ gem list capybara
To see if it's installed. If it isn't, install them both with:
$ gem install poltergeist
Capybara is a dependency of Poltergeist, and will be installed automatically.
Do that, and the script should work.
回答2:
Add poltergeist to your Gemfile gem 'poltergeist'
来源:https://stackoverflow.com/questions/29657046/loaderror-cannot-load-such-file-capybara-stand-alone-code