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

1

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

Bordereau answered 3/2, 2021 at 17:17 Comment(1)
So the answer is that Ruby thought you wanted to open a file, because you called Kernel#open and couldn't find it.Hernadez
T
35

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
Tartuffery answered 3/2, 2021 at 17:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.