Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LoadError: cannot load such file -- capybara Stand Alone Code

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?

like image 846
DillonCarter Avatar asked Apr 15 '15 17:04

DillonCarter


2 Answers

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.

like image 79
tompave Avatar answered Oct 18 '22 20:10

tompave


Add poltergeist to your Gemfile gem 'poltergeist'

like image 29
gilbertek Avatar answered Oct 18 '22 20:10

gilbertek