I've got this array coming back from a web scrape. Which looks like this:
[["formatted_sum_fees", "£5.60"],
["formatted_price", "£46.50"],
["formatted_sum_fees", "£4.50"],
["formatted_price", "£37.50"],
["formatted_sum_fees", "£3.30"],
["formatted_price", "£27.50"],
["formatted_sum_fees", "£3.30"],
["formatted_price", "£27.50"],
["formatted_sum_fees", "£4.50"],
["formatted_price", "£37.50"],
["formatted_sum_fees", "£4.50"],
["formatted_price", "£37.50"],
["formatted_sum_fees", "£4.50"],
["formatted_price", "£37.50"],
["formatted_sum_fees", "£5.60"],
["formatted_price", "£46.50"],
["formatted_sum_fees", "£4.50"],
["formatted_price", "£37.50"],
["formatted_sum_fees", "£5.60"],
["formatted_price", "£46.50"],
["formatted_sum_fees", "£4.50"],
["formatted_price", "£37.50"],
["formatted_sum_fees", "£3.30"],
["formatted_price", "£27.50"]]
So what happens is that it duplicates? So i'm wanting to change the above array to this (it will be different everytime so it'd need to remove duplicates.):
[["formatted_sum_fees", "£5.60"],
["formatted_price", "£46.50"],
["formatted_sum_fees", "£4.50"],
["formatted_price", "£37.50"],
["formatted_sum_fees", "£3.30"],
["formatted_price", "£27.50"]
Anything else that exists after this is a dupe.
What i'm needing is the fees and the price to be on a var so i can save it down to the database :)
Thanks Sam
extra Heres the raketask.
require "nokogiri"
require "open-uri"
namespace :task do
task test: :environment do
ticketmaster_url = "http://www.ticketmaster.co.uk/derren-brown-miracle-glasgow-04-07-2016/event/370050789149169E?artistid=1408737&majorcatid=10002&minorcatid=53&tpab=-1"
doc = Nokogiri::HTML(open(ticketmaster_url))
event_name = nil
ticket_price = nil
doc.xpath("//script[@type='text/javascript']/text()").each do |text|
if text.content =~ /more_options_on_polling/
ticket_price = text.to_s.scan(/\"(formatted_(?:price|sum_fees))\":\"(.+?)\"/)
byebug
end
end
end
end