Skip to content

Instantly share code, notes, and snippets.

@tobiasboyd
Created October 25, 2019 17:34
Show Gist options
  • Save tobiasboyd/7f155745da8b0d55584b9cf10c582198 to your computer and use it in GitHub Desktop.
Save tobiasboyd/7f155745da8b0d55584b9cf10c582198 to your computer and use it in GitHub Desktop.
require 'csv'
require 'nokogiri'
xml = File.read('googlebase_feed.xml')
doc = Nokogiri::XML(xml)
all_the_things = []
id, title, link, description, condition, price, sale_price, availability, image_link, ship_price, ship_method = ""
doc.xpath('//item').each do |file|
id = file.xpath("//*[name()='g:id']").first.text rescue "unset"
title = file.xpath("./title").first.text rescue "unset"
link = file.xpath("./link").first.text rescue "unset"
description = file.xpath("./description").first.text rescue "unset"
condition = file.xpath("//*[name()='g:condition']").first.text rescue "unset"
price = file.xpath("//*[name()='g:price']").first.text rescue "unset"
sale_price = file.xpath("//*[name()='g:sale_price']").first.text rescue "unset"
availability = file.xpath("//*[name()='g:availablity']").first.text rescue "unset"
image_link = file.xpath("//*[name()='g:image_link']").first.text rescue "unset"
ship_price = file.xpath("//*[name()='g:shipping/price']").first.text rescue "unset"
ship_method = file.xpath("//*[name()='g:shipping/shipping_label']").first.text rescue "unset"
all_the_things << [id, title, link, description, condition, price, sale_price, availability, image_link, ship_price, ship_method]
end
CSV.open('googlebase.csv', 'wb' ) do |row|
row << [id, title, link, description, condition, price, sale_price, availability, image_link, ship_price, ship_method]
all_the_things.each do |data|
row << data
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment