现在我正在从另一个 url 获取数据......这是我的代码:
require 'rubygems'
require 'nokogiri'
html = page.body
doc = Nokogiri::HTML(html)
doc.encoding = 'utf-8'
rows = doc.search('//table[@id = "MainContent_GridView1"]//tr')
@details = rows.collect do |row|
detail = {}
[
[:car, 'td[1]/text()'],
[:article, 'td[2]/text()'],
[:group, 'td[3]/text()'],
[:price, 'td[4]/text()'],
].each do |name, xpath|
detail[name] = row.at_xpath(xpath).to_s.strip
end
detail
end
@details
我试图通过数组而不是哈希来做到这一点。但我得到了很多错误......有什么想法吗?我需要它用于另一种方法...
我还在这里将数据(此结果哈希)设置为另一辆车:
oem_art = []
@constr_num.each do |o|
as_oem = get_from_as_oem(o.ARL_SEARCH_NUMBER)
if as_oem.present?
oem_art << as_oem
end
end
@oem_art = oem_art.to_a.uniq