我好像不能让它起作用。我想从不同的read服务器上拉出一个CSV文件,以便在我的应用程序中读取。我想这样称呼它:
url = 'http://www.testing.com/test.csv'
records = FasterCSV.read(url, :headers => true, :header_converters => :symbol)但这并不管用。我试着用谷歌搜索,得到的结果是这样的摘录:Practical Ruby Gems
因此,我尝试对其进行如下修改:
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)。
有人能告诉我怎么做吗?
发布于 2009-01-12 22:53:51
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
endhttp://www.ruby-doc.org/core/classes/OpenURI.html http://fastercsv.rubyforge.org/
发布于 2009-01-12 14:52:38
例如,我会使用Net::HTTP检索文件,并将其提供给FasterCSV
摘自ri Net::HTTP
require 'net/http'
require 'uri'
url = URI.parse('http://www.example.com/index.html')
res = Net::HTTP.start(url.host, url.port) {|http|
http.get('/index.html')
}
puts res.body发布于 2010-03-03 06:33:33
你只是有一个小小的打字错误。您应该使用FasterCSV.parse而不是FasterCSV.read
data = open('http://www.testing.com/test.csv')
records = FasterCSV.parse(data)https://stackoverflow.com/questions/435634
复制相似问题