19

i start to learn ruby and scraping and i try to open an url with open and i got

lib/scrapper.rb:7:in `initialize': No such file or directory @ rb_sysopen - https://en.wikipedia.org/wiki/Douglas_Adams (Errno::ENOENT) from lib/scrapper.rb:7:in `open' from lib/scrapper.rb:7:in `<main>'

And this is my code :

# frozen_string_literal: true

require 'rubygems'
require 'open-uri'
require 'nokogiri'

document = open("https://en.wikipedia.org/wiki/Douglas_Adams")

puts document

After some long hours of google research i don't find any solution 😭 I test open with this url to : http://www.krosmoz.com/fr/almanax thanks all 🧅

ps i'm on mac m1 don't know if they are compatibility issues

1
  • So the answer is that Ruby thought you wanted to open a file, because you called Kernel#open and couldn't find it. Commented Feb 3, 2021 at 22:41

1 Answer 1

36

The problem is likely that you are using ruby 3.0.0.

Under Ruby 2.7, I receive the following warning:

warning: calling URI.open via Kernel#open is deprecated, call URI.open directly or use URI#open

And under Ruby 3.0, it has been removed.

So the solution, per the warning:

document = URI.open("https://en.wikipedia.org/wiki/Douglas_Adams").read
Sign up to request clarification or add additional context in comments.

I was going to point out that says private method open' called for URI:Module (NoMethodError)` on eg Ruby 2.7... but not if you require "open-uri" first.

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.