Maxime Crespo
Maxime Crespo

Reputation: 229

Ruby open-uri can't open url (m1 mac)

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

Upvotes: 19

Views: 6883

Answers (1)

John Ledbetter
John Ledbetter

Reputation: 14183

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

Upvotes: 35

Related Questions