LoadError: cannot load such file — capybara Stand Alone Code

独自空忆成欢 提交于 2021-02-08 15:32:53

问题


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

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