我有这个 ruby 代码,它从互联网上获取一个 xml 文件并保存它。它将它保存到当前目录,但想将它保存到 specfik 目录。我怎么做?
require 'rubygems'
require 'nokogiri'
require 'open-uri'
base_url = 'SOME-URL'
extension = '.xml'
# the specfik dir
xml_dir = '/Users/admin/Documents/Projects/files/xmlfolder'
Nokogiri::HTML(open(base_url)).xpath("//a/@href").each do |src|
File.open(File.basename(src.value, File.extname(src.value)) + extension,'wb'){ |f|
f.write(open(src.value).read)
}
puts "Done with: #{base_url}"
end