How to fix "Errno::ENOENT: No such file or directory @ rb_sysopen"?

4.9k Views Asked by At

Super new to coding! I created a new project with rails new.

I'm trying to scrape a website, but I am getting an error Errno::ENOENT: No such file or directory @ rb_sysopen

require 'open-uri'
require 'nokogiri'
require 'pry'

def get_page
    link = "https://www.pokemon.com/us/pokedex/"
    doc = Nokogiri::HTML(open(link))
    #rest of code
end

get_page

Any help is appreciated. Thank you!

2

There are 2 best solutions below

0
CR7 On BEST ANSWER
link = "https://www.pokemon.com/us/pokedex/"
doc = Nokogiri::HTML(URI.open(link))

Just add the URI

0
Jörg W Mittag On

Kernel#open opens a file, IO stream, or subprocess. It doesn't open a URI:

open(path [, mode [, perm]] [, opt]) → io or nil

open(path [, mode [, perm]] [, opt]) {|io| block } → obj

Creates an IO object connected to the given stream, file, or subprocess.

OpenURI is used by calling the URI::open method:

Method: URI.open

.open(name, *rest, &block)Object

Allows the opening of various resources including URIs.

So, your code should look like this:

def get_page
  link = "https://www.pokemon.com/us/pokedex/"
  doc = Nokogiri::HTML(URI.open(link))
  #rest of code
end