如何修复 "Errno::ENOENT: No such file or directory @ rb_sysopen"?
How to fix "Errno::ENOENT: No such file or directory @ rb_sysopen"?
编码超级新手!我用 rails new
.
创建了一个新项目
我正在尝试抓取网站,但出现错误 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
感谢任何帮助。谢谢!
link = "https://www.pokemon.com/us/pokedex/"
doc = Nokogiri::HTML(URI.open(link))
只需添加 URI
Kernel#open
打开文件、IO 流或子进程。它不打开 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.
因此,您的代码应如下所示:
def get_page
link = "https://www.pokemon.com/us/pokedex/"
doc = Nokogiri::HTML(URI.open(link))
#rest of code
end
编码超级新手!我用 rails new
.
我正在尝试抓取网站,但出现错误 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
感谢任何帮助。谢谢!
link = "https://www.pokemon.com/us/pokedex/"
doc = Nokogiri::HTML(URI.open(link))
只需添加 URI
Kernel#open
打开文件、IO 流或子进程。它不打开 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.
因此,您的代码应如下所示:
def get_page
link = "https://www.pokemon.com/us/pokedex/"
doc = Nokogiri::HTML(URI.open(link))
#rest of code
end