Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 617
Maxime Crespo Avatar asked Feb 03 '21 17:02

Maxime Crespo


1 Answers

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
like image 143
John Ledbetter Avatar answered Nov 13 '22 21:11

John Ledbetter