Guest User

Untitled

a guest
Dec 12th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #Loop through each .olpOffer (product listing) and gather content from various elements
  2. parse_page.css('.olpOffer').each do |a|
  3. if a.css('.olpSellerName img').empty?
  4. seller = a.css('.olpSellerName').text.strip
  5. else
  6. seller = a.css('.olpSellerName img').attr('alt').value
  7. end
  8. offer_price = a.css('.olpOfferPrice').text.strip
  9. prime = a.css('.supersaver').text.strip
  10. shipping_info = a.css('.olpShippingInfo').text.strip.squeeze(" ").gsub!(/(n)/, '')
  11. condition = a.css('.olpCondition').text.strip
  12. fba = "FBA" unless a.css('.olpBadge').empty?
  13.  
  14. #Push data from each product listing into array
  15. arr.push(seller,offer_price,prime,shipping_info,condition,fba)
  16. end
  17. #Need to make each product listing's data begin in new row [HELP!!]
  18. CSV.open("file.csv", "wb") do |csv|
  19. csv << ["Seller", "Price", "Prime", "Shipping", "Condition", "FBA"]
  20.  
  21. end
  22. end
Add Comment
Please, Sign In to add comment