代码:
doc = Nokogiri::HTML(html)
showings = []
doc.css('.ok-product').each do |showing|
showing_id = showing['data-cart-id'].to_i
price = showing.at_css('.ok-product__price-main').text.gsub(/[\u0440\u0443\u0431.]/, '').strip
showings.push(
id: showing_id,
price: price
)
end
CSV.open("file.csv", "wb") do |csv|
csv << showings
end
我在单元格A1中获取csv中的数据:
{:id=>26999, :price=>"395,00"},"{:id=>26963, :price=>""254,00""}"...
需要将数据分解为单元格并删除不必要的符号。
答案 0 :(得分:2)
CSV.open("file.csv", "wb") do |csv|
showings.each do |id_price|
csv << [id_price[:id], id_price[:price]]
end
end