我似乎无法让它发挥作用。我想从不同的网络服务器中提取 CSV 文件以在我的应用程序中读取。我想这样称呼它:
url = 'http://www.testing.com/test.csv'
records = FasterCSV.read(url, :headers => true, :header_converters => :symbol)
但这是行不通的。我尝试用谷歌搜索,得到的只是以下摘录:
于是,我尝试修改如下:
require 'open-uri'
url = 'http://www.testing.com/test.csv'
csv_url = open(url)
records = FasterCSV.read(csv_url, :headers => true, :header_converters => :symbol)
...我得到一个can't convert Tempfile into String
错误(来自 FasterCSV gem)。
谁能告诉我如何进行这项工作?
require 'open-uri'
url = 'http://www.testing.com/test.csv'
open(url) do |f|
f.each_line do |line|
FasterCSV.parse(line) do |row|
# Your code here
end
end
end
http://www.ruby-doc.org/core/classes/OpenURI.html http://www.ruby-doc.org/core/classes/OpenURI.html
http://fastercsv.rubyforge.org/ http://fastercsv.rubyforge.org/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)