Ruby 该程序在Pry中工作,但在其他任何地方(Errno::EN0ENT)都没有这样的文件或目录

Ruby 该程序在Pry中工作,但在其他任何地方(Errno::EN0ENT)都没有这样的文件或目录,ruby,sitemap,Ruby,Sitemap,这是我正在使用的代码。试着做一些很酷的事情。目前我只想让这部分发挥作用 require 'nokogiri' require 'open-uri' require 'colorize' puts "Image sitemap generator".colorize(:blue) puts "Not compatibile with tiered sitemaps".colorize(:red) puts "v.0.1".colorize(:blue) puts "----------------

这是我正在使用的代码。试着做一些很酷的事情。目前我只想让这部分发挥作用

require 'nokogiri'
require 'open-uri'
require 'colorize'
puts "Image sitemap generator".colorize(:blue)
puts "Not compatibile with tiered sitemaps".colorize(:red)
puts "v.0.1".colorize(:blue)
puts "-----------------------------------------------------------------"
puts "Enter the site you'd like an image sitemap for?"
site = gets.chomp
path = "/sitemap.xml"
target = "#{site}#{path}"
sitemap = Nokogiri::HTML(open(target))
links = sitemap.xpath('//url/loc')
links.each do |link|
    puts link
end
它在我的机器上不工作,并给出错误:

imgsm.rb:12:in `initialize': No such file or directory - http://website.com/sitemap.xml (Errno::ENOENT)
    from imgsm.rb:12:in `open'
    from imgsm.rb:12:in `<main>'`

然而,它在pry和irb中工作得非常好。发生了什么,我该如何解决?这令人难以置信地沮丧。我尝试过删除Ruby、更新Ruby并返回到以前的版本。没有任何东西能解决这个问题

OpenURI所做的是使用monkey patches Kernel.open来打开远程文件。您得到的错误表明open将您的URL视为本地文件系统上文件的路径,进而表明未加载open uri模块。如果你能找出原因,你就能解决这个问题。谢谢你的提示。我会进行故障排除,但这可能有点超出我的技能水平。任何关于从哪里开始的想法都会很棒。谢谢你的时间。你是如何运行脚本的?使用ruby imgsm.rb?您发布的代码是否是imgsm.rb中包含的所有代码?两个问题都是。我使用的是ruby imgsm.rb,代码就是包含的所有内容。您能检查一下ruby底层pry的版本是否与您运行脚本时使用的版本相同吗?试试pry-version和ruby-version