Ruby脚本找不到CSV文件

时间:2017-06-13 23:48:19

标签: ruby

我有一个用Ruby编写的简单抓取工具,它应该抓取特定网站并将数据保存到CSV文件中,但是,当从Windows命令行运行它时,我收到此错误:

C:/Ruby24-x64/lib/ruby/2.4.0/csv.rb:1282:in `initialize': No such file or directory @ rb_sysopen - csv/boxers.csv (Errno::ENOENT)
    from C:/Ruby24-x64/lib/ruby/2.4.0/csv.rb:1282:in `open'
    from C:/Ruby24-x64/lib/ruby/2.4.0/csv.rb:1282:in `open'
    from boxers.rb:18:in `<main>'

这是剧本:

#!/usr/bin/env ruby

require 'csv'
require 'mechanize'

agent = Mechanize.new{ |agent| agent.history.max_size=0 }
agent.user_agent = 'Mozilla/5.0'

base = "http://baseurl.com/"

division = ARGV[0]

search_url = "http://baseurl.com/ratings.php?sex=M&division=#{division}&pageID="

path='//*[@id="mainContent"]/table/tr[position()>2]'

boxers = CSV.open("csv/file.csv","w")

url = search_url+"1"

begin
  page = agent.get(url)
rescue
  print "  -> error, retrying\n"
  retry
end


end

boxers.close

0 个答案:

没有答案