Gemfile
...
gem 'nokogiri'
...
In controller
doc = Nokogiri::HTML(open('http://google.com'))
And I got a error
Errno::ENOENT in SiteController#scrap
No such file or directory - http://google.com
app/controllers/site_controller.rb:6:in `initialize'
app/controllers/site_controller.rb:6:in `open'
app/controllers/site_controller.rb:6:in `scrap'
I tried delete Gemfile.lock and do "bundle install" again, but it's not resolved my problems.
rails 2.3.8
ruby 1.9.3p194
What am I doing wrong? Thanks in advance for your help
You need to require 'open-uri'
if you want to pass URLs to open()
. Additionally, you'll need to read the file after opening it:
require 'open-uri'
doc = Nokogiri::HTML(open('http://google.com').read)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With