Ruby Open-Uri Can't Open Url (M1 MAC)

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

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

Ruby open-uri throws an Bad uri error when I try to get a URL through user input. Why?

gets adds a new line character to the end of the string. I have used chomp on the gets to remove this below.

It should work now

require 'nokogiri'
require 'open-uri'

get_url = gets.chomp

doc = Nokogiri::HTML(open(get_url))
puts doc


Related Topics



Leave a reply



Submit