Rake 任务使用 nogokiri 获取 XML 流并将选定字段写入数据库
我正在尝试构建一个 rake 任务,它获取产品提要并将其添加到我的数据库中。
task :testme => :environment do
require 'nokogiri'
require 'zlib'
require 'open-uri'
@url = "http://some_url/filename.xml.gz"
@source = open((@url), :http_basic_authentication=>[USERID, "PASSWORD"])
@gz = Zlib::GzipReader.new(@source)
@result = @gz.read
@doc = Nokogiri::XML(@result)
@doc.xpath("//product").each do |item|
Product.create(:productname => product.css("name").text)
end
end
所以这工作正常,直到
@doc = Nokogiri::XML(@result)
引发 rake 错误
File name too long (repeating the content of xml- document)
这真的很令人困惑,因为我在模型中开发和测试了它,我可以在模型中读取、解压缩和搜索文件,然后使用 put 写入所需的字段。
你有主意吗?
干杯,
瓦尔
I am trying to build a rake tasks, that fetches a product feed and adds it to my db.
task :testme => :environment do
require 'nokogiri'
require 'zlib'
require 'open-uri'
@url = "http://some_url/filename.xml.gz"
@source = open((@url), :http_basic_authentication=>[USERID, "PASSWORD"])
@gz = Zlib::GzipReader.new(@source)
@result = @gz.read
@doc = Nokogiri::XML(@result)
@doc.xpath("//product").each do |item|
Product.create(:productname => product.css("name").text)
end
end
So this works fine until
@doc = Nokogiri::XML(@result)
which throws a rake error
File name too long (repeating the content of xml- document)
That's really confusing, because I developed and tested it in a model, where I could read, unzip and search the file and then write the desired fields with put.
Do you have an idea?
Cheers,
Val
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
明白了:
失踪了。
Got it:
was missing.